/**************************************************************************
 * @doc CPAC
 * @module CPACPRNT.C |
 * Source code for the CPAC Receipt handling functions.
 *
 * Product         :   SoftPay 2000 (Global Payment Methodology).
 * <nl>Developer   :   SoftPay Development Team (I_SP2000).
 * <nl>Notes       :
 *
 * @head3 CPAC Functions |
 * @index | CPAC
 * @end
 *
 * Copyright (c) 1996-2000 by VeriFone Inc. All rights reserved.
 *
 * No part of this software may be used, stored, compiled, reproduced,
 * modified, transcribed, translated, transmitted, or transferred, in any form
 * or by any means whether electronic, mechanical, magnetic, optical,
 * or otherwise, without the express prior written permission of VeriFone, Inc.
 *
 * Revision History
 * ------------------------------------------------------------------------
 $Log: /SoftPay/SPK2SIM/Source/CPACsrc/cpacprnt.c $
 ********************************************************************************/
#ifdef IMAM_LOG
#ifndef LOGSYS_FLAG
#define LOGSYS_FLAG
#endif
#endif

#include <project.h>
#define CPAC_CPKPRINT_C

#include <aclconio.h>
#include <txoinc.h>
#include <ascii.h>
#include <errno.h>
#include <applidl.h>
#include <printer.h>
#include <formater.h>
#include <message.h>
#include <stdlib.h>
#include <aclstr.h>
#include <string.h>
#include <actutil.h>
#include <acldev.h>

#include <define.h>
#include <sizes.h>
#include <transact.h>
#include <print.h>
#include <gds.h>
#include <lct.h>
#include <tct.h>
#include <pct.h>
#include <iit.h>
#include <ui.h>
#include <msg.h>
#include <msgfuncs.h>
#include <form.h>
#include <stats.h>
#include <paramrpt.h>
#include <logo.h>
#include <tran.h>
#include <hdt.h>
#include <report.h>
#include <mit.h>
#include <msgclrk.h>
#include <report.h>
#include <pform.h>
#include <format.h>
#include <settlbat.h>
#include <multilng.h>
#include <settle.h>
#include <clrkrpts.h>
#include <date.h>
#include <funcids.h>
#include <batmsg.h>
#include <trt.h>
#include <pbatch.h>
#include <aclstr.h>
#include <batch.h>
#include <tblutil.h> //CPAC2.1B
#include "cpacoper.h"
#include "cpacmsg.h"
#include <spdebug.h>
#include <init.h>
#include <util.h>
#include <confio.h>
#include <oper.h>
#include <entry.h>
#include <file.h>
#include <card.h>
#include <date.h>
#include <accum.h>
#include <accmsg.h>
#include <rcptsegs.h>
#include <rcptcmpt.h>
#include <udt.h>
#include <table.h>
#include <ifldtbl.h>
#include "cpacids.h"

#include "cpacsize.h"
#include "cpacprnt.h"
#include "cpacextn.h"
#include "cpacstl.h"
#include "cpacbat.h"
#include "sqautils.h"

#ifdef VXEMVAPP
#include <libvoy.h>
#include <cardslot.h>
#include <EMVCWrappers.h>
#include <common.h>
#include <EMVCStructs.h>
#include <vxemvap.h>
#include <emvlib.h>
#include <estfuncs.h>
#include <mvtfuncs.h>
#include <mvt.h>
#include <est.h>
#include "../EMVSrc/EMVids.h"
#include "../EMVSrc/EMVsrcdef.h"
#include "../EMVSrc/EMViso.h"
#include "../EMVSrc/EMVprnt.h"
#endif

#ifdef ICICI
	#include "..\icicsrc\icicmsg.h"
	#include "..\icicsrc\icicids.h"
#endif /* ICICI  */

#ifdef AMEX_SOC

//#include "..\axapsrc\axapids.h"

#endif /* AMEX_SOC */

#ifdef DOWNLOAD_MULTIPLE_LOGO
extern int inMultipleDownloadLogo(int);
#endif /* DOWNLOAD_MULTIPLE_LOGO */

#ifdef SHELL_FLEET
#include "../shellsrc/shellids.h"
#endif
#define PRINTER_350         3
#define STATS_DAY_REPORT    1
#define STATS_WEEK_REPORT   2
static const char* STATS_FRM1 = "STATS.FRM";
static unsigned char szMyScratch1[30];

/* Saritha_b1 .......Start.....Reprint Settlement Report */

// #ifdef TLFB  (Made this feature as the part of CPAC Base Application)

CPAC_SETTLE_HEADER srCPACSettleHeader;
CPAC_SETTLE_MIDDLE srCPACSettleMiddle;
CPAC_SETTLE_BOTTOM srCPACSettleBottom;

extern int inDBFileExists(const char* pszFileName);
extern int inDBCreateFile(const char* pszFileName,unsigned int uiRecordSize);
extern int inDBWriteRecord(const char* pszFileName,int inRecNum,const unsigned char* pucBuf);
extern int inDBReadRecord(const char* pszFileName,unsigned int uiRecNum,unsigned char* pucBuf);
extern int inDBTotalRecords(const char* pszFileName);
extern int inDBRemoveFile(const char* pszFileName);

// #endif /* TLFB */   (Made this feature as the part of CPAC Base Application)

/* Saritha_b1 .......End.....Reprint Settlement Report */




extern int inCPACPrintStatsData(int inDay,STATS* psrStats);
int inCPACPrintClerkTotalsBottom(TRANSACTION_OBJECT* pobTran,PRINTER_OBJECT* obPrinter,CLERK_TOTS_REC* psrGrandTots,int inFormFeed);
void vdCPACSetClerkHeaderCondition(int inReportTop,int inReportType,int inNewClerk,int inCurrencyFlag);
#ifdef SHELL_FLEET
extern inShellPrintProductLines(PRINTER_OBJECT* obPrinter,TRANSACTION_OBJECT* pobTran);
extern char szKbdBuf[CARD_SIZE + 1];
#endif /*  SHELL_FLEET */
void vdCPACGetMessageFromReceiptFile(long lnMessageIndex,char* szMessageBuffer,TRANSACTION_OBJECT* pobTran);

extern void vdFormatCITIDate(char* pchDate);

#define KEY_ONERPT  1
#define KEY_ALLRPT  2

#ifdef HKGM
extern void vdFormatCITIDate(char* pchDate);
#endif /* HKGM */
#ifdef CITI_IND
extern void vdFormatCITIDate(char* pchDate);
#endif /*CITI_IND*/
long lnCPACMiddleCondition;
extern unsigned short uinCurrentState;
CPAC_CUST_DETAIL_REPORTS_FIELDS srCPACDet;

VS_BOOL fCITICustomerReceipt(TRANSACTION_OBJECT* pobTran);
extern int inCITIFlowPrintReceipt(TRANSACTION_OBJECT* pobTran);
extern VS_BOOL fIsIndependentBatch(int inHostNum);
extern void vdBatchDCOpen(TRANSACTION_OBJECT* pobTran);  // 1.4
int inGlobalHostHandle = 0;
extern int inGlobalMerchantHandle;

VS_BOOL fCPACCustomerCopyReceipt(TRANSACTION_OBJECT* pobTran);

extern VS_BOOL fGetTRTf1(TRANSACTION_OBJECT* pobTran);
extern VS_BOOL fGetTRTf2(TRANSACTION_OBJECT* pobTran);
extern VS_BOOL fGetTRTf3(TRANSACTION_OBJECT* pobTran);
void vdCPACMakeReceiptAfterResp (TRANSACTION_OBJECT *pobTran)
{
	int len;
	char szPan[PAN_SIZE + 1], acct[PAN_SIZE + 1];//, szDate[DATE_SIZE + 1];

	short shTempSugTipPer1,shTempSugTipPer2, shTempSugTipPer3;
	long lnSChg = 0L, lnBaseAmt, lnSubTotAmt, lnTipAmt1 , lnTipAmt2 , lnTipAmt3 ;

	/* Edi - wongslam - variable for masking */
	CPAC_REC srCPAC;
	int needMaskingMenu = 0;
	int maskingMenuC = 0, maskingMenuM = 0, maskingMenuB = 0;
	/***********************************/
	#ifdef  ICICI
		unsigned char szMyScratch[30];
		unsigned char szCITITempTime[TIME_SIZE+1];
		unsigned char  szCITITempDate[DATE_SIZE+1];
       	memset(szMyScratch, 0x0, sizeof(szMyScratch));
		memset(szCITITempTime, 0x0, sizeof(szCITITempTime));
		memset(szCITITempDate, 0x0, sizeof(szCITITempDate));
		//venu corrected for date and time printing.
		if(inGGOpCode() != REPRINT_LAST_OPERATION )
		{
			if(inGGOpCode() != REPRINT_ANY_OPERATION)
			{
				if((pobTran->srTRTRec.TransactionCode == CPAC_PHIL_ADJUST)||(pobTran->srTRTRec.TransactionCode == ADJUST) || (pobTran->srTRTRec.TransactionCode  ==VOID) ||(pobTran->srTRTRec.TransactionCode == PRE_COMP) ||(pobTran->srTRTRec.TransactionCode==TIP_ADJUST))
				{

					inGetBatchFieldData (&pobTran->srBRec, CITI_DATE, szCITITempDate, DATE_SIZE);
					inGetBatchFieldData (&pobTran->srBRec, CITI_TIME, szCITITempTime, TIME_SIZE);
				}
				else
					vdSetReceiptDateAndTime(pobTran);
			}
		}
		if((inGGOpCode() == REPRINT_LAST_OPERATION))
			vdSetReceiptDateAndTime(pobTran);

		if(inGGOpCode() == REPRINT_ANY_OPERATION)
		{
			inGetBatchFieldData (&pobTran->srBRec, CITI_DATE, szCITITempDate, DATE_SIZE);
			inGetBatchFieldData (&pobTran->srBRec, CITI_TIME, szCITITempTime, TIME_SIZE);
              	if(atoi((char*)szCITITempDate) >0)
              	{
				if(atoi((char*)szCITITempTime) > 0)
              	   	{
					memcpy(pobTran->srBRec.szDate, szCITITempDate,DATE_SIZE);
					memcpy (pobTran->srBRec.szTime, szCITITempTime, TIME_SIZE);}}
					vdSetReceiptDateAndTime(pobTran);
				}
				inGetBatchFieldData (&pobTran->srBRec, CITI_PIP_TRANS_CODE, szMyScratch, 19);
				if(strlen((char *)szMyScratch) >0)
				{
        				memset(szMyScratch1,'\0', sizeof(szMyScratch1));
					strcpy((char *)szMyScratch1, (char *)szMyScratch);
				}

    				inLoadINIRec(0);
				if(fGetAddDataFlag() == VS_TRUE)
				{
					if((pobTran->srBRec.inCode == SALE) ||(pobTran->srBRec.inCode == SALE_OFFLINE) ||(pobTran->srBRec.inCode == REFUND) ||
						(pobTran->srBRec.inCode == REFUND_OFFLINE) ||(pobTran->srBRec.inCode == CITI_DEBIT_SALE)
						|| ( pobTran->srBRec.inCode==CASH_ADV))
					{
						strcpy(srRcpt.unFrm.srReceipt.szGenBuf5,"INF:");
						if(strlen((char *)szMyScratch) >0)
							strcat (srRcpt.unFrm.srReceipt.szGenBuf5, (char *)szMyScratch);
						else
						{
							strcat (srRcpt.unFrm.srReceipt.szGenBuf5, (char *)szMyScratch1);
						}
					}
				}

	#else

		/*if((pobTran->inTransactionCode == CPAC_PHIL_ADJUST)||(pobTran->inTransactionCode == ADJUST))
		{
			vdGetDate(szDate,MMDDYY);
			strlcpy(srRcpt.szDate,&(szDate[4]),2);
			strlcpy(srRcpt.szDate+2,pobTran->srBRec.szDate,2);
			strlcpy(srRcpt.szDate+4,&(pobTran->srBRec.szDate[2]),2);
			vdFormatDate(srRcpt.szDate);
			strcpy(srRcpt.szTime,pobTran->srBRec.szTime);
			vdFormatTime(srRcpt.szTime);
		}
		else*/

		vdSetReceiptDateAndTime(pobTran);

	#endif  /*  ICICI   */

	strcpy(srRcpt.unFrm.srReceipt.szApprovalCode, pobTran->srBRec.szAuthCode);
    	memset(acct,0,sizeof(acct));
	memset(szPan,0,sizeof(szPan));
	strcpy(acct, pobTran->srBRec.szPAN);
	memset(srRcpt.unFrm.srReceipt.szAcctNum,0x00,sizeof(srRcpt.unFrm.srReceipt.szAcctNum));
	if(pobTran->srBRec.inTranCardType == DEBIT_CARD || pobTran->srBRec.inTranCardType == EBT_CARD) {
		len = strlen(acct);
		strlcpy(szPan,acct,len);
	}
	else
		strcpy(szPan, acct);
	/***  - wongslam - disable print masking for specific menu based transaction code ***/
		vdLoadCPACParams(&srCPAC);
		if (needMaskingMenu ||
			( pobTran->srBRec.inPrintOption == PRT_MERCH && srCPAC.fMaskPANinMRcpt) || // fGetCPACMaskPANinMRcpt())||
			( pobTran->srBRec.inPrintOption == PRT_CUST && srCPAC.fMaskPANinCRcpt) || // fGetCPACMaskPANinCRcpt())||
			( pobTran->srBRec.inPrintOption == PRT_BANK && srCPAC.fMaskPANinBRcpt) || // fGetCPACMaskPANinBRcpt())||
			( pobTran->srBRec.inPrintOption == (PRT_MERCH | PRT_DUPLICATE) && srCPAC.fMaskPANinMRcpt) || // fGetCPACMaskPANinMRcpt())||
			( pobTran->srBRec.inPrintOption == (PRT_CUST | PRT_DUPLICATE) && srCPAC.fMaskPANinCRcpt) || // fGetCPACMaskPANinCRcpt())||
			( pobTran->srBRec.inPrintOption == (PRT_BANK | PRT_DUPLICATE) && srCPAC.fMaskPANinBRcpt)) // fGetCPACMaskPANinBRcpt()))
		{
			if (!needMaskingMenu ||
					(( pobTran->srBRec.inPrintOption == PRT_MERCH && maskingMenuM) ||
					( pobTran->srBRec.inPrintOption == PRT_CUST && maskingMenuC) ||
					( pobTran->srBRec.inPrintOption == PRT_BANK && maskingMenuB) ||
					( pobTran->srBRec.inPrintOption == (PRT_MERCH | PRT_DUPLICATE) && maskingMenuM) ||
					( pobTran->srBRec.inPrintOption == (PRT_CUST | PRT_DUPLICATE) && maskingMenuC) ||
					( pobTran->srBRec.inPrintOption == (PRT_BANK | PRT_DUPLICATE) && maskingMenuB))){
#ifdef HKGM
				?
				memset(srRcpt.unFrm.srReceipt.szAcctNum,0x00,sizeof(srRcpt.unFrm.srReceipt.szAcctNum));
				vdFormatPAN(pobTran, szPan, srRcpt.unFrm.srReceipt.szAcctNum, sizeof (srRcpt.unFrm.srReceipt.szAcctNum));
#else
#if LEN_REMOVED
				?
			 	vdCPACFormatPAN(szPan, srRcpt.unFrm.srReceipt.szAcctNum); /* Added for Formatting 4444 4444 4444 4444 */
#endif /* LEN_REMOVED */
				vdFormatPAN(pobTran, szPan, srRcpt.unFrm.srReceipt.szAcctNum, sizeof (srRcpt.unFrm.srReceipt.szAcctNum));
				//LOG_PRINTFF((0x08L, "FORMAT PAN"));

				
#endif /* HKGM */
			} else {
				memset(srRcpt.unFrm.srReceipt.szAcctNum,0x00,sizeof(srRcpt.unFrm.srReceipt.szAcctNum));
				strcpy(srRcpt.unFrm.srReceipt.szAcctNum, szPan);
			}
		}	
	/*************************************************************************/
	else
	{
		int i=0;
		memset(srRcpt.unFrm.srReceipt.szAcctNum, 0x00, sizeof(srRcpt.unFrm.srReceipt.szAcctNum));
		for (i=0; i<20; i=i+4){
			if (strlen(&szPan[i]) > 6){
				strncat(srRcpt.unFrm.srReceipt.szAcctNum, &szPan[i], 4);
				strcat(srRcpt.unFrm.srReceipt.szAcctNum, " ");
			} else {
				strcat(srRcpt.unFrm.srReceipt.szAcctNum, &szPan[i]);
				break;
			}
		}
		//strcpy(srRcpt.unFrm.srReceipt.szAcctNum,szPan);
		//vdFormatPAN(pobTran, szPan, srRcpt.unFrm.srReceipt.szAcctNum, sizeof (srRcpt.unFrm.srReceipt.szAcctNum));
		//LOG_PRINTFF((0x08L, "NO FORMAT PAN"));	
	}
	//Kelvin_F2 --- end: masking PAN by new flags in CPAC
    //To print "Chip" as entry mode for chip card transactions
	  if (pobTran->srBRec.inChipStatus != NOT_USING_CHIP) {
		strcpy(srRcpt.unFrm.srReceipt.szEntryMethod, "DIP");
		if ((pobTran->srBRec.inChipStatus ==  IMAM_CHIP_TAP_CARD) || (pobTran->srBRec.inChipStatus ==  IMAM_MSD_TAP_CARD)){ //VISAVAWE
			strcpy(srRcpt.unFrm.srReceipt.szEntryMethod, "tap");
		} 
      } else if (pobTran->srBRec.fManual) {
 	       strcpy(srRcpt.unFrm.srReceipt.szEntryMethod,"Manual");
	  } else {
    	   strcpy(srRcpt.unFrm.srReceipt.szEntryMethod,"Swipe");
	  }

	if (pobTran->srBKey.fOffline)
            strcpy(srRcpt.unFrm.srReceipt.szApprovalType,"Offine");
       else
            strcpy(srRcpt.unFrm.srReceipt.szApprovalType,"Online");

    if ( pobTran->srBRec.lnSChgAmount > 0L )
        lnSChg = pobTran->srBRec.lnSChgAmount;

    memset(srRcpt.unFrm.srReceipt.szSChg,0,sizeof(srRcpt.unFrm.srReceipt.szSChg));
    if (pobTran->srBRec.inTranCardType == DEBIT_CARD)
    {
        sprintf(srRcpt.unFrm.srReceipt.szSChg,   SUBSTITUTE_LD, lnSChg);
        vdFormatAmount(srRcpt.unFrm.srReceipt.szSChg, VS_TRUE);

		lnSubTotAmt = (pobTran->srBKey.lnTotalOfTransactionAmount
                       - lnSChg - pobTran->srBRec.lnCashBackAmount);
        sprintf(srRcpt.unFrm.srReceipt.szSubTotAmt, SUBSTITUTE_LD, lnSubTotAmt);
		vdFormatAmount(srRcpt.unFrm.srReceipt.szSubTotAmt, VS_TRUE);

    }

    sprintf(srRcpt.unFrm.srReceipt.szTotAmt, SUBSTITUTE_LD,
            (pobTran->srBKey.lnTotalOfTransactionAmount));
    vdFormatAmount(srRcpt.unFrm.srReceipt.szTotAmt, VS_TRUE);


/* if print disclaimer flag is on, propogate disclaimer
   buffers */

   /* LENIN CPAC Disclaimer is hard coded in TPL FIle as per core */

   /** Calculations for suggested tips ****/


if(fGetSugTipOn() == VS_TRUE)

/* set default amounts if flag on and field is empty */
    {

       shTempSugTipPer1 = inGetSugTipPer1();

       if(shTempSugTipPer1 <= 0)
        {
         shTempSugTipPer1 = 1500;
        /* vdSetSugTip1(shTempSugTipPer1);*/
        }

       sprintf(srRcpt.szTipPct1, SUBSTITUTE_D,shTempSugTipPer1);

	   //vdPutDecPoint(srRcpt.szTipPct1);  //LENIN ATL
	   vdFormatAmount(srRcpt.szTipPct1, VS_TRUE);
       shTempSugTipPer2 = inGetSugTipPer2();

       if(shTempSugTipPer2 <= 0)
       {
         shTempSugTipPer2 = 2000;
     /*    vdSetSugTip2(shTempSugTipPer2);*/
       }

	   sprintf(srRcpt.szTipPct2, SUBSTITUTE_D,shTempSugTipPer2);
//	   vdPutDecPoint(srRcpt.szTipPct2);//LENIN ATL
		vdFormatAmount(srRcpt.szTipPct2, VS_TRUE);
       shTempSugTipPer3 = inGetSugTipPer3();

       if(shTempSugTipPer3 <= 0)
       {
         shTempSugTipPer3 = 2500;
/*         vdSetSugTip3(shTempSugTipPer3);*/
       }


		sprintf(srRcpt.szTipPct3, SUBSTITUTE_D,shTempSugTipPer3);
       // vdPutDecPoint(srRcpt.szTipPct3);//LENIN ATL
		vdFormatAmount(srRcpt.szTipPct3, VS_TRUE);

		lnTipAmt1 = ((pobTran->srBRec.lnBaseTransactionAmount / 10000L) * shTempSugTipPer1);
		lnTipAmt1 += (((pobTran->srBRec.lnBaseTransactionAmount % 10000L) * shTempSugTipPer1) / 10000L);

        /*ComputePercent(shTempSugTipPer1,pobTran->srBRec.lnBaseTransactionAmount,lnTipAmt1);*/
        sprintf(srRcpt.szTipAmt1, SUBSTITUTE_LD,lnTipAmt1);
//        vdPutDecPoint(srRcpt.szTipAmt1);//LENIN ATL
		vdFormatAmount(srRcpt.szTipAmt1, VS_TRUE);

		lnTipAmt2 = ((pobTran->srBRec.lnBaseTransactionAmount / 10000L) * shTempSugTipPer2);
		lnTipAmt2 += (((pobTran->srBRec.lnBaseTransactionAmount % 10000L) * shTempSugTipPer2) / 10000L);

        /*ComputePercent(shTempSugTipPer2,pobTran->srBRec.lnBaseTransactionAmount,lnTipAmt2);*/
        sprintf(srRcpt.szTipAmt2, SUBSTITUTE_LD,lnTipAmt2);
//        vdPutDecPoint(srRcpt.szTipAmt2);//LENIN ATL
		vdFormatAmount(srRcpt.szTipAmt2, VS_TRUE);

		lnTipAmt3 = ((pobTran->srBRec.lnBaseTransactionAmount / 10000L) * shTempSugTipPer3);
		lnTipAmt3 += (((pobTran->srBRec.lnBaseTransactionAmount % 10000L) * shTempSugTipPer3) / 10000L);

        /*ComputePercent(shTempSugTipPer3,pobTran->srBRec.lnBaseTransactionAmount,lnTipAmt3);*/
        sprintf(srRcpt.szTipAmt3, SUBSTITUTE_LD,lnTipAmt3);
//        vdPutDecPoint(srRcpt.szTipAmt3);//LENIN ATL
        vdFormatAmount(srRcpt.szTipAmt3, VS_TRUE);
    }

	sprintf(srRcpt.unFrm.srReceipt.szTipAmt, SUBSTITUTE_LD, pobTran->srBRec.lnTipAmount);
    sprintf(srRcpt.unFrm.srReceipt.szBaseAmt, SUBSTITUTE_LD, pobTran->srBRec.lnBaseTransactionAmount);

    /* Saritha_b1.......Start........Printing Cash Back Amount on the receipt for Cash Back transaction */
	sprintf(srRcpt.unFrm.srReceipt.szCBack, SUBSTITUTE_LD, pobTran->srBRec.lnCashBackAmount);

    /* Saritha_b1.......Start........Printing Cash Back Amount on the receipt for Cash Back transaction */

    if (pobTran->srBRec.inPrintOption & PRT_DUPLICATE)
    {
        lnBaseAmt = (pobTran->srBKey.lnTotalOfTransactionAmount
                           - pobTran->srBRec.lnTaxAmount - pobTran->srBRec.lnTipAmount -
                             pobTran->srBRec.lnCashBackAmount - lnSChg);
        sprintf(srRcpt.unFrm.srReceipt.szBaseAmt, SUBSTITUTE_LD, lnBaseAmt);
    }
    else
    {
        if ( pobTran->srBKey.fVoided )
        {
            sprintf (srRcpt.unFrm.srReceipt.szTotAmt, SUBSTITUTE_LD,
                     pobTran->srBKey.lnTotalOfTransactionAmount);
            vdFormatAmount(srRcpt.unFrm.srReceipt.szTotAmt, VS_TRUE);
            lnBaseAmt = (pobTran->srBKey.lnTotalOfTransactionAmount
                           - pobTran->srBRec.lnTaxAmount - pobTran->srBRec.lnTipAmount -
                             pobTran->srBRec.lnCashBackAmount - lnSChg);
            sprintf(srRcpt.unFrm.srReceipt.szBaseAmt, SUBSTITUTE_LD, lnBaseAmt);
        }
        if (pobTran->fAdjust)
        {
       //sprintf (srRcpt.unFrm.srReceipt.szGenBuf1, SUBSTITUTE_LD,
         //            (pobTran->srBRec.lnOrigTotalTransactionAmount-pobTran->srBRec.lnOldTipAmount));
    sprintf (srRcpt.unFrm.srReceipt.szGenBuf1, SUBSTITUTE_LD,
                     (pobTran->srBRec.lnOldTotalTransactionAmount-pobTran->srBRec.lnOldTipAmount));




          /*  vdFormatAmount(srRcpt.unFrm.srReceipt.szBaseAmt);  Base Amount has the old Amount. Lenin 13/04/2000 */
		 sprintf (srRcpt.unFrm.srReceipt.szBaseAmt, SUBSTITUTE_LD,
                     pobTran->srBRec.lnBaseTransactionAmount);

        }
    }
/*  COMMENT
    if(inGGCode() == PRE_AUTH)
//Kelvin_F2 --- start: format the amount field for pre_auth
#ifndef HKGM
        sprintf(srRcpt.unFrm.srReceipt.szBaseAmt, "%06.6ld", pobTran->srBRec.lnBaseTransactionAmount);
#endif
#ifdef HKGM
	{
        sprintf(srRcpt.unFrm.srReceipt.szBaseAmt, SUBSTITUTE_LD, pobTran->srBRec.lnBaseTransactionAmount);
		vdFormatAmount(srRcpt.unFrm.srReceipt.szBaseAmt, VS_TRUE);
	}
#endif
//Kelvin_F2 --- end: format the amount field for pre_auth
    else
*/
        vdFormatAmount(srRcpt.unFrm.srReceipt.szBaseAmt, VS_TRUE);
        vdFormatAmount(srRcpt.unFrm.srReceipt.szTipAmt, VS_TRUE);
         vdFormatAmount(srRcpt.unFrm.srReceipt.szGenBuf1, VS_TRUE);
	#ifdef ICICI
       	if((pobTran->srBRec.inCode== CASH_ADV) && (pobTran->srBRec.inOrgCode == VOID))
     		{
        		sprintf(srRcpt.unFrm.srReceipt.szBaseAmt, SUBSTITUTE_LD, pobTran->srBRec.lnBaseTransactionAmount);
			vdFormatAmount(srRcpt.unFrm.srReceipt.szBaseAmt, VS_TRUE);
		}
	#endif /*  ICICI  */

             /* Saritha_b1.......Start........Printing Cash Back Amount on the receipt for Cash Back transaction */

        vdFormatAmount(srRcpt.unFrm.srReceipt.szCBack, VS_TRUE);

           /* Saritha_b1.......Start........Printing Cash Back Amount on the receipt for Cash Back transaction */
	{// Addition for SSP and AIRLINE
		if (pobTran->srBRec.inPlan>=1 && pobTran->srBRec.inPlan<=3 && pobTran->srBRec.inInstallments>=2) {
			sprintf(srRcpt.unFrm.srReceipt.szGenBuf3, "P-%03d", pobTran->srBRec.inPlan);
			sprintf(srRcpt.unFrm.srReceipt.szGenBuf5, "%ld", pobTran->srBRec.lnDepositAmount);
			vdFormatAmount(srRcpt.unFrm.srReceipt.szGenBuf5, VS_TRUE);
			sprintf(srRcpt.unFrm.srReceipt.szGenBuf4, "%02d Months", pobTran->srBRec.inInstallments);
			sprintf(srRcpt.unFrm.srReceipt.szGenBuf6, "%ld", pobTran->srBRec.lnAmountPerInstallment);
			vdFormatAmount(srRcpt.unFrm.srReceipt.szGenBuf6, VS_TRUE);
		}

		if (pobTran->srBRec.inPlan>=4 && pobTran->srBRec.inInstallments>=1) {
			if (fGetImamAirlineTrx()) {
				strcpy(srRcpt.unFrm.srReceipt.szGenBuf2, "");
			} else {
				sprintf(srRcpt.unFrm.srReceipt.szGenBuf2, "%ld", strtol(pobTran->srBRec.szCustNum, NULL, 10));
				vdFormatAmount(srRcpt.unFrm.srReceipt.szGenBuf2, VS_TRUE);
			}
			sprintf(srRcpt.unFrm.srReceipt.szGenBuf5, "%ld", pobTran->srBRec.lnDepositAmount);
			vdFormatAmount(srRcpt.unFrm.srReceipt.szGenBuf5, VS_TRUE);
			sprintf(srRcpt.unFrm.srReceipt.szGenBuf4, "PC-%02d", pobTran->srBRec.inInstallments);
			sprintf(srRcpt.unFrm.srReceipt.szGenBuf6, "%ld", pobTran->srBRec.lnAmountPerInstallment);
			vdFormatAmount(srRcpt.unFrm.srReceipt.szGenBuf6, VS_FALSE);
			sprintf(srRcpt.unFrm.srReceipt.szGenBuf3, "%ld", pobTran->srBKey.lnTotalOfTransactionAmount - pobTran->srBRec.lnDepositAmount);
			vdFormatAmount(srRcpt.unFrm.srReceipt.szGenBuf3, VS_TRUE);
		}

		if ((fGetImamAirlineTrx()) && (strlen(pobTran->srBRec.szCustNum))) { 
			strcpy(srRcpt.unFrm.srReceipt.szGenBuf2, pobTran->srBRec.szCustNum);
		}

		if ((fGetImamPrivateLabel()) && (strlen(pobTran->srBRec.szCustNum))) { 
			strcpy(srRcpt.unFrm.srReceipt.szGenBuf2, pobTran->srBRec.szCustNum);
		}

		if (pobTran->srTRTRec.TransactionCode == POINT_BAL_INQ)  { // for Online Redemption App BNI
			sprintf(srRcpt.unFrm.srReceipt.szGenBuf2, "%ld", strtol(pobTran->srBRec.szCustNum, NULL, 10));
			vdFormatAmount(srRcpt.unFrm.srReceipt.szGenBuf2, VS_TRUE);
			LOG_PRINTFF((0x08L, "srRcpt.unFrm.srReceipt.szGenBuf2 = %s", srRcpt.unFrm.srReceipt.szGenBuf2));
			LOG_PRINTFF((0x08L, "pobTran->srBRec.szCustNum = %s", pobTran->srBRec.szCustNum));
			LOG_PRINTFF((0x08L, "pobTran->srBKey.lnTotalOfTransactionAmount = %ld", pobTran->srBKey.lnTotalOfTransactionAmount));
		}
		vdImamReformatDate(srRcpt.szDate);
	}
}





int inCPACPrintReceiptBottom(TRANSACTION_OBJECT* pobTran) {
#ifndef IMAM_REMOVE
    //int hReprint;  CPAC_LINT_RMD
    DB_FILE dbReprintFile;
#ifdef SHELL_FLEET
    unsigned char stCardType[CARD_TYPE_SIZE + 1]; //For SHELL Host
    int inTranCardType;
#endif

    /**/pdebug(("--inPrintReceiptBottom--"));/**/

#ifdef DOWNLOAD_MULTIPLE_LOGO
    inMultipleDownloadLogo(1);
#endif

    if (inGetPrinterType() == NOPRINTER || !fGetEnablePrinter())
        return(VS_SUCCESS);
    /* vdCPACMakeReceiptAfterResp(pobTran); */
    /*CPAC LENIN #if TBD_CPAC  */
    vdSetPrintReceiptConditions(pobTran);
    /* CPAC LENIN #endif  TBD_CPAC */

    if (!pobTran->srTRTRec.PrintReceipt && !(pobTran->srBRec.inPrintOption & PRT_DUPLICATE))
        return(VS_SUCCESS);

    if ((inGGCode() == PRE_COMP) && (!fPrintCloseTab(pobTran)))
        return(VS_SUCCESS);

    if ((inGGCode() == PRE_AUTH) && (fGetOpenTabOptRec() == VS_FALSE))
        return(VS_SUCCESS);

    if (fGetEnablePrinter())
        vdDisplayMessageFromFile(PRINTING_MSG, STATUS_MSG);



    if (fGetDemoMode() == VS_TRUE)
        strcpy(srRcpt.unFrm.srReceipt.szRefCustNumber, "010203040506");
    /*      else if ( pobTran->srBKey.fOffline==VS_TRUE) {
                strcpy(srRcpt.unFrm.srReceipt.szRefCustNumber, " ");
            } LENIN COMMENTED THE CODE */
    else
        vdGetCPACRetRefNum(&pobTran->srBRec, (unsigned char *) srRcpt.unFrm.srReceipt.szRefCustNumber);
    // CPAC_LINT type-casted 2nd argument with (unsigned char *)
    //  strcpy(srRcpt.unFrm.srReceipt.szRefCustNumber,srISO.pszField37);

    vdGetCPACUserInvNum(&pobTran->srBRec, (unsigned char *) srRcpt.szTipPct1);
    // CPAC_LINT type-casted 2nd argument with (unsigned char *)

    if (inCPACPrintReceiptMiddle(&obPrinter))
        return(VS_ERR);
    /* CPAC LENIN #if TBD_CPAC */
    vdSetPrintReceiptConditions(pobTran);
    /* CPAC LENIN #endif  TBD_CPAC */
    //  if (inGGCode() == AUTH_ONLY)//1.4
    //      lnMiddleCondition &= 0xFFFBFFFF;

#ifdef SHELL_FLEET
    memcpy(stCardType, szKbdBuf + CARD_TYPE_OFFSET, CARD_TYPE_SIZE);
    stCardType[1] = '\0';
    /* convert stCardType to int */
    inTranCardType = *stCardType - '0';
    if ((inTranCardType == STANDALONE_CARD) || (inTranCardType == VEHICLE_CARD) || (inTranCardType == DRIVER_CARD))
        inShellPrintProductLines(&obPrinter, pobTran);
#endif /* SHELL_FLEET */


    if (inCPACPrintReceiptBottomLines(&obPrinter, pobTran))
        return(VS_ERR);

    /* CPAC LENIN #if TBD_CPAC */
    vdSetReceiptFooterConditions(pobTran);
    /* CPAC LENIN #endif  TBD_CPAC */
    /* CPAC LENIN #if TBD_CPAC */

    if (inPrintReceiptFooterLines(&obPrinter))
        return(VS_ERR);
    /* CPAC LENIN #endif  TBD_CPAC */




    /* Added for new Reprint Functionality */

    if (db_open(&dbReprintFile, REPRINT_FILE_NAME, SIZE_BATCH_KEY, (O_TRUNC | O_CREAT | O_RDWR)) < 0)
        return(VS_ERR);

    if (inWriteBatchData(&dbReprintFile, &pobTran->srBKey, &pobTran->srBRec, DB_APPEND) != VS_SUCCESS) {

        vdSGErrorMessage(BATCH_ERR_MSG);
        return(VS_ERR);
    }

    if (inCloseBatch(&dbReprintFile) != VS_SUCCESS)
    {
        vdSGErrorMessage(BATCH_ERR_MSG);
	}

    pobTran->fPreprinted = VS_FALSE;
#endif //IMAM_REMOVE
    return(VS_SUCCESS);
}





int inCPACPrintReceiptMiddle(PRINTER_OBJECT* obPrinter) {

    if (inPrintLines(obPrinter, CPAC_MIDDLE_START, CPAC_MIDDLE_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
        return(VS_ERR); /* LENIN CPAC */

    return(VS_SUCCESS);
}

int inCPACPrintReceiptBottomLines(PRINTER_OBJECT* obPrinter,TRANSACTION_OBJECT* pobTran) {
    /* changed NOSIGN_LINE to BOTTOM_END */
    long lnAmountCondition  ;
    lnAmountCondition = 0L;

#if 0
        if (pobTran->fAdjust==VS_TRUE)   {
            lnAmountCondition|=0x10000L;
            lnAmountCondition|=0x400000L;
        }
        //else
        if (pobTran->fTipAdjust == VS_TRUE) {
            lnAmountCondition = 0L;
            lnAmountCondition|=0x200000L;
            lnAmountCondition|=0x8L;
            lnAmountCondition|=0x40000L;
        }
        //else
        if (pobTran->srBRec.fTipEntered== VS_TRUE) {
            lnAmountCondition = 0L;
            lnAmountCondition|=0x200000L;
            if (pobTran->srBRec.lnTipAmount==0L) {
                lnAmountCondition|=0x2L;
                //lnAmountCondition|=0x40000L;
            }
            else {
                //lnAmountCondition = 0L;
                if(pobTran->fAdjust == VS_TRUE)
                    lnAmountCondition|=0x10000L;
                else
                lnAmountCondition|=0x40000L;
                lnAmountCondition|=0x8L;

            }
        }


#endif /* 0 */


    if ((pobTran->fAdjust == VS_TRUE) && (pobTran->fTipAdjust == VS_TRUE)) {
        lnAmountCondition = 0x0L;
        if (pobTran->srBRec.fTipEntered == VS_TRUE) {
            if (pobTran->srBRec.lnTipAmount == 0L)
                lnAmountCondition |= 0x2L;
            else
                lnAmountCondition |= 0x8L;
        }

        lnAmountCondition |= 0x200L;
        lnAmountCondition |= 0x40000L;
        lnAmountCondition |= 0x400000L;
    } else if ((pobTran->fAdjust == VS_TRUE) && (pobTran->srBRec.fTipEntered == VS_TRUE)) {
        lnAmountCondition = 0x0L;
        if (pobTran->srBRec.fTipEntered == VS_TRUE) {
            if (pobTran->srBRec.lnTipAmount == 0L)
                lnAmountCondition |= 0x2L;
            else
                lnAmountCondition |= 0x8L;
        }

        lnAmountCondition |= 0x200L;
        lnAmountCondition |= 0x40000L;
        lnAmountCondition |= 0x400000L;
    } else if (pobTran->fAdjust == VS_TRUE) {
        lnAmountCondition = 0x0L;
        lnAmountCondition |= 0x10000L;
        lnAmountCondition |= 0x400000L;
        if (pobTran->srBRec.lnTipAmount != 0L)
            lnAmountCondition |= 0x8L;
    } else if (pobTran->fTipAdjust == VS_TRUE) {
        lnAmountCondition = 0L;
        if (pobTran->srBRec.fTipEntered == VS_TRUE) {
            if (pobTran->srBRec.lnTipAmount == 0L)
                lnAmountCondition |= 0x2L;
            else
                lnAmountCondition |= 0x8L;
        }
        lnAmountCondition |= 0x200000L;
        //lnAmountCondition|=0x8L;
        if (pobTran->srBRec.lnTipAmount != 0L)
            lnAmountCondition |= 0x40000L;
    } else if (pobTran->srBRec.fTipEntered == VS_TRUE) {
        lnAmountCondition = 0;
        if (pobTran->srBRec.lnTipAmount == 0L)
            lnAmountCondition |= 0x2L;
        else {
            lnAmountCondition |= 0x8L;
            lnAmountCondition |= 0x40000L;
        }

        lnAmountCondition |= 0x200000L;
        //lnAmountCondition|=0x8L;
    }

    if (pobTran->srBKey.fVoided) {
        if ((pobTran->fAdjust == VS_TRUE) || (pobTran->fTipAdjust == VS_TRUE))
            lnAmountCondition |= 0x40000L;
        else
            lnAmountCondition |= 0x80000L;
    }
#ifdef HKGM //Kelvin_F2 --- start: display a blank line of TIP when tip mode turn on.
    else if (inGetTipProcessing() > TIP_OFF) {
        lnAmountCondition |= 0x200000L;
        lnAmountCondition |= 0x2L;
    }
    #endif //Kelvin_F2 --- end: display a blank line of TIP when tip mode turn on.

    //if (pobTran->srBRec.fTipEntered== VS_TRUE)

    if (inPrintLines(obPrinter, AMOUNT_START, AMOUNT_END, NO_BL_LINE, lnAmountCondition) != VS_SUCCESS)
        return(VS_ERR);

    if (inPrintLines(obPrinter, CPAC_SIGN_LINE_START, CPAC_SIGN_LINE_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
        return(VS_ERR);/* LENIN CPAC */
    //  lnBottomCondition=0L;
    /*  if (uinCurrentState==CITI_PFR_BEGIN_CUST_PRINTING_RECEIPT)
        lnBottomCondition=0x10000000L;
     else if (uinCurrentState==CITI_PFR_BEGIN_BANK_PRINTING_RECEIPT)
        lnBottomCondition=0x20000000L; */
    if (inPrintLines(obPrinter, CPAC_BOTTOM_START, CPAC_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
        return(VS_ERR);/* LENIN CPAC */
    return(VS_SUCCESS);
}

int inCPACPrintReportHeader(TRANSACTION_OBJECT* pobTran) {
    return(VS_SUCCESS);
}



int inCPACReportInit(TRANSACTION_OBJECT* pobTran) {
    /** /pdebug(("--inDetailReportOperation--"));*/

    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }
    inGetReport1Template();
    return(inCPACPrintDetailReport(pobTran, &obPrinter));
}




int inCPACPrintDetailReport(TRANSACTION_OBJECT* pobTran,PRINTER_OBJECT* obPrinter) {
    int     /* inShift, CPAC_LINT_REMOVED */ inNewCurr,
    inReportTop = VS_TRUE;
    //char    chShift CPAC_LINT_REMOVED ;
    int inResult,
    inNeedGrTot,
    inCnt = 0;
    int inNeedCurrTot,
    inCurr = 0;
    int inNumberOfRecordsinBatch;
    int inPrintDetail = VS_FALSE;
    int inStart,
    inStop,
    inNumberOfMerchants,
    inMerch = 0;
    int inHostIndex;
    int inCurrencyFlag = VS_FALSE;
	int     inImamHostIndex;
	int     inImamCurrencyIndex;


    /* Shift total accumulators */
    // DETAIL_TOTALS srShTot; CPAC_LINT_REMOVED
    /* Grand total accumulators */
    DETAIL_TOTALS srGrTot;
    /* Currency total accumulators */
    DETAIL_TOTALS srCurrTot;

#ifdef DOWNLOAD_MULTIPLE_LOGO
    inMultipleDownloadLogo(0);
#endif

    for (inHostIndex = 0; inHostIndex < MAX_HOSTS; inHostIndex++) {
        if (inLoadHDTRec(inHostIndex) != VS_SUCCESS) {
            vdSGErrorMessage(HDT_ERR_MSG21);
            return(VS_ERR);
        }  //CPAC2.1B

        if (fGetAllowMultiCurrency()) //CPAC2.1B
        {
            inCurrencyFlag = VS_TRUE;
            break;
        }
    }

    inHostIndex = inGetHostHandle();
    inGlobalHostHandle = inGetHostHandle(); //LENIN
	inImamHostIndex = inGetHostHandle(); //
    if (inLoadHDTRec(inHostIndex) != VS_SUCCESS) {
        vdSGErrorMessage(HDT_ERR_MSG21);
        return(VS_ERR);
    }  //CPAC2.1B

	inImamCurrencyIndex = inGetCurrencyIdx();  //

    if (fChkHostBatches(pobTran, inGetMerchantNum() - 1) == VS_TRUE)  // remember changes made here
    {
        vdDisplayMessageFromFile(BATCH_EMPTY_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }

	#ifdef ICICI
	//For ICICI
		if(strcmp(szGetHostName(),"AXAP")!=0)
		{

    			if (inGetHostTranCnt(pobTran) < 1)
			{
        			vdDisplayMessageFromFile(BATCH_EMPTY_MSG, WARNING_MSG);
        			//  return(BATCH_EMPTY_MSG);
        			vdSGErrorMessage(0L);
        			return (VS_SUCCESS);
    			}
		}

	#else

		 if ( inGetHostTranCnt(pobTran) < 1 )
		 {
		 	vdDisplayMessageFromFile( BATCH_EMPTY_MSG, WARNING_MSG);
          		//  return(BATCH_EMPTY_MSG);
     		 	vdSGErrorMessage(0L);
        		return (VS_SUCCESS);
    		}

	#endif  /*   ICICI   */

    //   vdSetMerchantNum(inGlobalMerchantHandle);//CPAC2.1B
    /* determine how many merchants should be printed */


    inNumberOfMerchants = inSelectOneAllMID(pobTran, fGetMultiMerchPrompt()); //CPAC2.1B
    if (inNumberOfMerchants == 0)
        return(VS_SUCCESS);
    if (inNumberOfMerchants == inGetMITTotRecs()) {
        inStart = 1;
        inStop = inGetMITTotRecs();
    } else if (inNumberOfMerchants == 1) {
        inStart = inGetMerchantNum();//CPAC2.1B
        inStop = inGetMerchantNum();//CPAC2.1B
    } else {
        inStart = 1;
        inStop = 0;
    }


    inMerch = inGetMerchantNum();//CPAC2.1B
    /*   for (inMerch = inStart; inMerch <= inStop; inMerch++)
      { */ // LENIN 1.4 for Multi merchant support
    if (inLoadMITRec(inMerch - 1) != VS_SUCCESS)
        return(VS_ERR);
    strlcpy(srRcpt.szMerchantName, szGetMerchantText(), sizeof(srRcpt.szMerchantName));
    //lnGetBatchNum();
    //sprintf(srRcpt.szBatchNum, "%ld", lnGetBatchNum());
    long2str(srRcpt.szBatchNum, lnGetBatchNum());
    inZeroDetailTotals(&srGrTot);
    inNeedGrTot = 0;  /* bb1 */
    vdSetMerchantNum(inGlobalMerchantHandle);//CPAC2.1B
    inNumberOfRecordsinBatch = inGetDCBatchRecCnt(pobTran);
    /* Check whether the batch is empty or not */
    if (inNumberOfRecordsinBatch == 0) {
        //vdDisplayMessageFromFile( SKIP_MSG, STATUS_MSG);
        vdCloseDCBatch(pobTran); /* bb1 */
    } else /* bb1 */ {
        /* bb1 */
        vdBatchDCOpen(pobTran);//LENIN 1.4
        if (fGetEnablePrinter())
            vdDisplayMessageFromFile(PRINTING_MSG, STATUS_MSG);

        memset(srRcpt.unFrm.srReceipt.szSChg, 0x00, sizeof(srRcpt.unFrm.srReceipt.szSChg));

        vdMakeReportHeader(pobTran);
        inPrintReceiptHeader(pobTran);
        strlcpy(srRcpt.szHostName, szGetHostName(), (int)sizeof(srRcpt.szHostName));
        //inPrintReportHeader(pobTran, obPrinter);
        inNeedCurrTot = 0;
        for (inCurr = 0; inCurr < inGetCSTTotRecs(); inCurr++) {
            if (inLoadCSTRec(inCurr) != VS_SUCCESS) {
                vdSGErrorMessage(CST_ERR_MSG);
                return(VS_ERR);
            }
			if (inImamCurrencyIndex != inCurr) continue;  // to avoid double printing detail report header
            inCnt = 0;
            inZeroDetailTotals(&srCurrTot);
            pobTran->srBKey.inCurrencyIndex = inCurr;
            strcpy(srRcpt.unFrm.srDet.srMid.szCSymbol, szGetCurSymbol());


            inNewCurr = VS_TRUE;

            srRcpt.unFrm.srDet.srMid.inTotalTipCount = 0; /* mb1 */
            srRcpt.unFrm.srDet.srMid.lnTotalTipAmt = 0;   /* mb1 */
            pobTran->srBKey.inHDTIndex = inHostIndex;
            /* Print online records */
                if((inResult = inGetDCKeyBatchRec (pobTran, KEY_CURRENCY, &pobTran->srBKey, DB_FIRST)) != VS_EOB)
                {
                    do
                    {
                    //pobTran->srBKey.inHDTIndex=inHostIndex;

                    if (inGGCode() != AUTH_ONLY && inGGCode() != IMAM_CARDVER) {
                        if (inNewCurr) {
                            inNewCurr = VS_FALSE;
                            /* Header condition should not print report title except at top of report */
                            vdCPACSetDetailHeaderCondition(inReportTop, inCurrencyFlag);
                            inReportTop = VS_FALSE;

#ifdef CPACCLRK_C
                            if (inGetClerkMode() == NO_CLERK)
                                strcpy(srRcpt.szClerkId, " ");
                            else if (inGetApplicationType() == RETAIL)
                                                                    /* lmw 1/28/99 use Message file --not hard coded label
                                                                    strcpy(srRcpt.szClerkId, "Clrk");*/
                                vdGetMessageFromFile(RPT_CLERK_MSG4, srRcpt.szClerkId);
                            else
                                                                    /* lmw 1/28/99 use Message file --not hard coded label
                                                                    strcpy(srRcpt.szClerkId, "Srvr");*/
                                vdGetMessageFromFile(RPT_SERVER_MSG4, srRcpt.szClerkId);
#else
                            strcpy(srRcpt.szClerkId, " ");
#endif
#ifdef CITI_PHIL
                            //Kelvin_F2 --- start: no need to mask TID

#ifdef MASK_TID_AND_MID
                            vdMaskCitiMTID();
#endif                          //Kelvin_F2 --- end: no need to mask TID
                            //Kelvin_F2 --- end: no need to mask TID
                            pad(srRcpt.szBatchNum, srRcpt.szBatchNum, '0', inGetBatchNumSize(), RIGHT);

#endif /* CITI_PHIL */
                            //Kelvin_f2 --- fix for Host name problem
                            //vdGetHDTHostName(srRcpt.szHostName);//CPAC2.1B
                            //strlcpy(srRcpt.szHostName,szGetHostName(), (int)sizeof(srRcpt.szHostName));
                            //inCPACPrintSummaryMiddle (obPrinter, pobTran,&inReportTop , 0); /* LENIN mb1 */
                            //leo_noSourceSafe
#ifdef CITI_IND
                            vdGetDate(srRcpt.szDate, YYMMDD);
                            vdFormatCITIDate(srRcpt.szDate);
#endif /*CITI_IND*/
							vdImamReformatDate(srRcpt.szDate); //LIEM
                            if (inPrintLines(obPrinter, CPAC_DETAIL_TOP_START, CPAC_DETAIL_TOP_END, NO_BL_LINE, lnHeaderCondition) != VS_SUCCESS)
                                return(VS_ERR);
                        }

                        if (pobTran->srBKey.inHDTIndex == inHostIndex)
                            if (inCPACPrintDetailMiddle(obPrinter, pobTran, &srCurrTot) != VS_SUCCESS)
                                return(VS_ERR);
                        inCnt++;

                        if (act_kbd_pending_test(KEY_CANCEL))
                            return(VS_ESCAPE);
                    }
                    inResult = inGetDCKeyBatchRec(pobTran, KEY_CURRENCY, &pobTran->srBKey, DB_NEXT);
                } while (inResult != VS_EOB);
                }
                /* end of key */

                /* Bottom */
            if (inCnt > 0) {
                if (inGetCSTTotRecs() > 1 && inCurrencyFlag == VS_TRUE)
                    inNeedCurrTot++;
                else
                    inNeedGrTot++;
            }
            inAccumDetailTotals(&srGrTot, &srCurrTot);
            srCurrTot.inVoidCnt = 0;

            if (inGetCSTTotRecs() > 1) {
                if ((inNeedCurrTot > 0) && (inCnt > 0)) {
                    /* Currency Totals */
                    inSetDetailPrintTotals(&srCurrTot);
                    vdSetDetailBottomCondition(pobTran, inPrintDetail, inNumberOfRecordsinBatch, 1, &srCurrTot);

                    if (inPrintLines(obPrinter, CPAC_DETAIL_BOTTOM_START, CPAC_DETAIL_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
                        return(VS_ERR);
                }
            }
        }/* end currency for loop */
        inPrintDetail = VS_TRUE;

        /*  Always need grand totals if NO_SHIFT */
        if (inNeedGrTot > 0) {
            /*  Use default currency for host for grand totals */
            if (inLoadCSTRec(inGetCurrencyIdx()) != VS_SUCCESS) {
                vdSGErrorMessage(CST_ERR_MSG);
                return(VS_ERR);
            }
            /* Grand Totals */
            // inSetDetailPrintTotals(&srGrTot);
            /* Param 3 indicates this is the GrandTotal bottom */
            vdSetDetailBottomCondition(pobTran, inPrintDetail, inNumberOfRecordsinBatch, 2, &srGrTot);

            //if(inPrintLines(obPrinter, DETAIL_BOTTOM_START, DETAIL_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
            //  return(VS_ERR);
        }
        //else
        // if(inPrintLines(obPrinter, DETAIL_FORM_FEED, DETAIL_BOTTOM_END, NO_BL_LINE, 0x80000000) != VS_SUCCESS)
        //     return(VS_ERR);

        memset(srRcpt.szErrorMessage, '\0', sizeof(srRcpt.szErrorMessage));
        memset(srRcpt.szStatusMessage, '\0', sizeof(srRcpt.szStatusMessage));

        vdCloseDCBatch(pobTran); /* bb1 */
    } /* bb1 */
    /*  } */ // Multi merchant support /* merchant loop */

	{// to correct currency detail report printout
		LOG_PRINTFF((0x08L, "HostRef/CST = [%d-%s] - inCPACPrintDetailReport - END0", shGetHostGroupRef(), szGetCurSymbol()));
		inGlobalHostHandle = inImamHostIndex;
		inLoadHDTRec(inImamHostIndex);
		inLoadCSTRec ( inGetCurrencyIdx());
	}

	if (fGetImamReportPerCard()){
		inImamPrintDetailGrandTotal(obPrinter, pobTran, &inReportTop, inNumberOfMerchants);  // for BNI
	} else {
		inCPACPrintDetailGrandTotal(obPrinter, pobTran, &inReportTop, inNumberOfMerchants);
	}
	
    if (inPrintLines(obPrinter, 198, 198, NO_BL_LINE, 0L) != VS_SUCCESS)
        return(VS_ERR);

    vdSGErrorMessage(0L);
    return (VS_SUCCESS);
}



int inCPACPrintDetailMiddle(PRINTER_OBJECT* obPrinter,TRANSACTION_OBJECT* pobTran,DETAIL_TOTALS* psrDetTot) {
    /* For Advice Upload requests invoice number needs to be
    picked up from the batch record - Field62 will be loaded
    from the batch record before this function is called
    */
    vdCPACMakeDetailMiddle(pobTran, psrDetTot);
    vdSetDetailMiddleCondition(pobTran);
#if CITI_PHIL
    lnMiddleCondition = 0L;
#endif /* CITI_PHIL */
    //leo_nosourcesafe
#ifdef CITI_IND
    lnMiddleCondition = 0L;
#endif /* CITI_IND */
    return(inPrintLines(obPrinter, CPAC_DETAIL_MIDDLE_START, CPAC_DETAIL_MIDDLE_END, NO_BL_LINE, lnMiddleCondition));
}

void vdCPACSetDetailHeaderCondition(int inReportTop,int inCurrencyFlag) {
    if (inGetPrinterType() == NOPRINTER || !fGetEnablePrinter())
        return;
    lnHeaderCondition = formater_set_flags(inReportTop, (inReportTop && fGetDemoMode() == VS_TRUE), (fGetCashBack()), (inGetTipProcessing() > TIP_OFF),

        (inGetApplicationType() == RETAIL && inGetClerkMode() != NO_CLERK),
        (inGetApplicationType() == RETAIL && inGetClerkMode() == NO_CLERK),
        (inGetApplicationType() == RESTAURANT && inGetClerkMode() != NO_CLERK),
        (inGetApplicationType() == RESTAURANT && inGetClerkMode() == NO_CLERK),

        inGetMITTotRecs() > 1,
        0,
        0,
        0,

        (inGetShiftType() != NO_SHIFT),
        (inGetCSTTotRecs() > 1 && inCurrencyFlag == VS_TRUE),
        0,
        0,

        0,
        0,
        0,
        0,

        (inGetTipProcessing() > TIP_OFF && fGetCashBack()),
        (inGetTipProcessing() > TIP_OFF && !(fGetCashBack())),
        (inGetTipProcessing() == TIP_OFF && fGetCashBack()),
        (inGetTipProcessing() == TIP_OFF && !(fGetCashBack())),

        0,
        0,
        0,
        0,

        0,
        0,
        0,
        0, -1);
}

/*********************************************************************************************
* @func void | vdCPACMakeDetailMiddle |
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
* @parm DETAIL_TOTALS * | psrDetTot |
*
* @rdesc VOID
*
* @end
**********************************************************************************************/

void vdCPACMakeDetailMiddle(TRANSACTION_OBJECT* pobTran,DETAIL_TOTALS* psrDetTot) {
    int len = 0;
    double baseamt = 0.00;
    int inTransType = 0;
    char acctnum[PAN_SIZE + 1];
    char invnum[INV_NUM_SIZE + 1];
    char szTransName[MESSAGE_SIZE + 1];
    TRANSACTION_OBJECT obTran; /* bb1 */
    unsigned char ucIITTempRec[SIZE_IIT_REC + 1];
    int inIssuer;
    char szExpDate[EXP_DATE_SIZE + 1];
    /* Load TRT locally for batch record */
    inLoadTRTRec(&obTran, pobTran->srBRec.inCode); /* bb1 */

    memset(acctnum, 0x00, sizeof(acctnum));
    memset(srRcpt.unFrm.srDet.srMid.szCType, 0x00, sizeof(srRcpt.unFrm.srDet.srMid.szCType));
    memset(srRcpt.szTipAmt, 0x00, sizeof(srRcpt.szTipAmt));

    memset(srRcpt.unFrm.srDet.srMid.szCashBack, 0x00, sizeof(srRcpt.unFrm.srDet.srMid.szCashBack));

    if (pobTran->srBRec.lnMessage)
        vdGetMessageFromFile(pobTran->srBRec.lnMessage, srCPACDet.szTranType);






    long2str(invnum, pobTran->srBKey.lnInvNum);
    pad(srRcpt.unFrm.srDet.srMid.szInvNum, invnum, '0', inGetInvNumSize(), RIGHT);

    strcpy(acctnum, pobTran->srBRec.szPAN);

    len = strlen(acctnum);

    strcpy(srRcpt.unFrm.srDet.srMid.szTotalCBAmt, acctnum); /* SzTotalCBAmt is be recycled to print PAN */



    if (!pobTran->srBKey.fVoided)
        sprintf(srRcpt.unFrm.srDet.srMid.szTot, SUBSTITUTE_LD, pobTran->srBKey.lnTotalOfTransactionAmount);
    else {
        //    strcpy(srRcpt.unFrm.srDet.srMid.szTot, "000");/* Void was printing zero */
        sprintf(srRcpt.unFrm.srDet.srMid.szTot, SUBSTITUTE_LD, pobTran->srBKey.lnTotalOfTransactionAmount);
    }
    //    vdPutDecPoint(srRcpt.unFrm.srDet.srMid.szTot); //LENIN ATL
    vdFormatAmount(srRcpt.unFrm.srDet.srMid.szTot, VS_FALSE);
    vdTrimLeadSpaces(srRcpt.unFrm.srDet.srMid.szTot);
    baseamt = (double) (pobTran->srBKey.lnTotalOfTransactionAmount - pobTran->srBRec.lnTaxAmount - pobTran->srBRec.lnTipAmount - pobTran->srBRec.lnSChgAmount - pobTran->srBRec.lnCashBackAmount);

    /** /pdebug(("baseamt=%ld",baseamt));*/
    /** /pdebug(("Tot=%ld",pobTran->srBKey.lnTotalOfTransactionAmount));*/
    /** /pdebug(("Tax=%ld",pobTran->srBRec.lnTaxAmount));*/
    /** /pdebug(("Tip=%ld",pobTran->srBRec.lnTipAmount));*/
    /** /pdebug(("SChg=%ld",pobTran->srBRec.lnSChgAmount));*/
    /** /pdebug(("CB=%ld",pobTran->srBRec.lnCashBackAmount));*/

    if (!pobTran->srBKey.fVoided && !fRefundTrans(pobTran))
        inTransType = SALE;
    else if (fRefundTrans(pobTran) && !pobTran->srBKey.fVoided) /* bb1 */
        inTransType = REFUND;
    else
        inTransType = VOID;

    switch (inTransType) {
    case    SALE:
        psrDetTot->dbTipAmt += (double) pobTran->srBRec.lnTipAmount;
        psrDetTot->inSaleCnt++;
        psrDetTot->dbSaleAmt += baseamt;
        if ((pobTran->srBRec.lnTipAmount > 0L))
            psrDetTot->inTipCnt++;
        if (pobTran->srBRec.fTaxEntered && (pobTran->srBRec.lnTaxAmount > 0L))
            psrDetTot->inTaxCnt++;                             /* bb1 */
        psrDetTot->dbTaxAmt += (double) pobTran->srBRec.lnTaxAmount;    /* bb1 */
        psrDetTot->dbGrandAmt += (double) (pobTran->srBKey.lnTotalOfTransactionAmount);
        /* Surcharge amount have value */
        if ((pobTran->srBRec.lnSChgAmount > 0L) && (HOST_NETID_TEST)) {
            psrDetTot->dbSurCharge += (double) pobTran->srBRec.lnSChgAmount;
            psrDetTot->inSurchgCnt ++;
        }
        if (pobTran->srBRec.lnTipAmount > 0L)
            sprintf(srRcpt.szTipAmt, SUBSTITUTE_LD, pobTran->srBRec.lnTipAmount);
        else
            strcpy(srRcpt.szTipAmt, "000");  /* bb1 */

        vdDb2Str(baseamt, srRcpt.szAmt);
        // sprintf(srRcpt.szAmt, SUBSTITUTE_LD, baseamt);
        psrDetTot->inGrandCnt++;
        break;

    case    REFUND:
        psrDetTot->dbTipAmt -= (double) pobTran->srBRec.lnTipAmount;
        psrDetTot->inRefCnt++;
        psrDetTot->dbRefAmt += baseamt;
        if ((pobTran->srBRec.lnTipAmount > 0L))
            psrDetTot->inTipCnt++;
        if (pobTran->srBRec.fTaxEntered && (pobTran->srBRec.lnTaxAmount > 0L))
            psrDetTot->inTaxCnt++;                             /* bb1 */
        psrDetTot->dbTaxAmt -= (double) pobTran->srBRec.lnTaxAmount;    /* bb1 */
        psrDetTot->dbGrandAmt -= (double) pobTran->srBKey.lnTotalOfTransactionAmount; /* do not add refunds*/
        if (pobTran->srBRec.lnSChgAmount > 0L) {
            psrDetTot->dbSurCharge -= (double) pobTran->srBRec.lnSChgAmount;
            psrDetTot->inSurchgCnt ++;
        }
        if (pobTran->srBRec.lnTipAmount > 0L)
            sprintf(srRcpt.szTipAmt, SUBSTITUTE_LD, pobTran->srBRec.lnTipAmount);
        else
            strcpy(srRcpt.szTipAmt, "000");

        //sprintf(srRcpt.szAmt, SUBSTITUTE_LD, baseamt);
        vdDb2Str(baseamt, srRcpt.szAmt);
        psrDetTot->inGrandCnt++;
        break;

    case    VOID:
        // strcpy (srRcpt.szAmt,"000");
        /* update void tran counts */
        ++psrDetTot->inVoidCnt;
        strcpy(srRcpt.szTipAmt, "000");
        if (pobTran->srBRec.lnCashBackAmount)
            strcpy(srRcpt.unFrm.srDet.srMid.szCashBack, "000");
        /* Do not allow VOID AutoDecrement to go neg. */
        psrDetTot->inGrandCnt = (psrDetTot->inGrandCnt > 0 ? psrDetTot->inGrandCnt-- : psrDetTot->inGrandCnt);
        break;

    default:
        break;
    }

    if (inGetTipProcessing() > TIP_OFF) {
        //vdPutDecPoint(srRcpt.szTipAmt);//LENIN ATL
        vdFormatAmount(srRcpt.szTipAmt, VS_FALSE);
    } else
        strcpy(srRcpt.szTipAmt, " ");

    //    vdPutDecPoint(srRcpt.szAmt);// LENIN ATL  /* pj1 - fix ITO #106 & ATL #18*/
    vdFormatAmount(srRcpt.szAmt, VS_FALSE);
    vdTrimLeadSpaces(srRcpt.szAmt);
    if (!fGetCashBack())
        strcpy(srRcpt.unFrm.srDet.srMid.szCashBack, " ");
    else {
        /*
         *      Only INC Amount and Count if CashBack was really entered.
         */
        if (pobTran->srBRec.lnCashBackAmount && inTransType != VOID) {
            psrDetTot->dbCBAmt += (double) pobTran->srBRec.lnCashBackAmount;
            psrDetTot->inCBackCnt++;
            sprintf(srRcpt.unFrm.srDet.srMid.szCashBack, SUBSTITUTE_LD, pobTran->srBRec.lnCashBackAmount);
        }
        //        vdPutDecPoint(srRcpt.unFrm.srDet.srMid.szCashBack);// LENIN ATL
        vdFormatAmount(srRcpt.unFrm.srDet.srMid.szCashBack, VS_FALSE);
    }


    if (!pobTran->srBKey.fVoided)
        strcpy(srRcpt.unFrm.srDet.srMid.szTransType, obTran.srTRTRec.TranAbbrev);   /* bb1 */
    else {
        strcpy(srRcpt.unFrm.srDet.srMid.szTransType, "V");
        strncat(srRcpt.unFrm.srDet.srMid.szTransType, obTran.srTRTRec.TranAbbrev, 1); /* bb1 */
    }
    /* if (pobTran->srBRec.lnMessage)
            vdGetMessageFromFile( pobTran->srBRec.lnMessage,
                                 srRcpt.unFrm.srDet.srMid.szTransType); */
    /* CPAC LENIN #if TBD_CPAC */

    //   inIssuer= atoi(pobTran->srBRec.szIssueNumber); (Saritha_b1 commented)

    inIssuer = (inGetIssuerNum() - 1);
    if ((inLoadIITRecFromStruct(inIssuer, ucIITTempRec)) == VS_ERR)
        vdSGErrorMessage(IIT_ERR_MSG21);

    // strcpy (srRcpt.unFrm.srDet.srMid.szTotalTaxAmt,szGetIssuerLabel());
    //strlcpy(srRcpt.unFrm.srDet.srMid.szTotalTaxAmt, szGetIssuerLabelFromStruct(ucIITTempRec), CLABEL_SIZE);
	strcpy(srRcpt.unFrm.srDet.srMid.szTotalTaxAmt, szGetCardLabel());  //LIEM to correct detail report
    //vdGetIssuerLabel(srRcpt.unFrm.srDet.srMid.szTotalTaxAmt);  /*szTotalTaxAmt is recycled to print the Card Label */
    /* CPAC LENIN #endif  TBD_CPAC */

    if (inGetClerkMode() == NO_CLERK)
        strcpy(srRcpt.szClerkId, " ");
    else
        strlcpy(srRcpt.szClerkId, pobTran->srBKey.szClerkId, CLERK_ID_SIZE);


    /* LENIN ADDED */
    memset(srRcpt.szTransName, '\0', sizeof(srRcpt.szTransName));
    memset(srRcpt.unFrm.srDet.srMid.szTransType, 0x00, sizeof(srRcpt.unFrm.srDet.srMid.szTransType));
    if (pobTran->srBRec.lnMessage)              /* mb1 */
        vdCPACGetMessageFromReceiptFile(pobTran->srBRec.lnMessage, szTransName, pobTran);
    if (pobTran->srBKey.fVoided == VS_TRUE) {
        vdCPACGetMessageFromReceiptFile(VOID_MSG6, srRcpt.unFrm.srDet.srMid.szTransType, pobTran);
        pad(srRcpt.unFrm.srDet.srMid.szTransType, srRcpt.unFrm.srDet.srMid.szTransType, ' ', strlen(srRcpt.unFrm.srDet.srMid.szTransType) + 1, LEFT);
    }



    strcat(srRcpt.unFrm.srDet.srMid.szTransType, szTransName);

    /* LENIN ENDED */

	#ifdef ICICI
		strcpy(srRcpt.unFrm.srDet.srMid.szExpDate , pobTran->srBRec.szExpDate);
	#else
		 if (strlen(pobTran->srBRec.szExpDate) > 0)
		{
        		strcpy(szExpDate, pobTran->srBRec.szExpDate);
        		sprintf(srRcpt.unFrm.srDet.srMid.szExpDate, "%.2s/%.2s", szExpDate + 2, szExpDate);
    		}
	#endif /* ICICI  */

    strcpy(srRcpt.unFrm.srDet.srMid.szTotalCBAmt, pobTran->srBRec.szPAN); /* SzTotalCBAmt is be recycled to print PAN */
    strcpy(srRcpt.unFrm.srDet.srMid.szApprovalCode, pobTran->srBRec.szAuthCode);

#ifdef CITI_IND
    strcpy(srRcpt.unFrm.srDet.srMid.szTotalSchgAmt, pobTran->srBRec.szDate);
    vdFormatDate(srRcpt.unFrm.srDet.srMid.szTotalSchgAmt);

    strcpy(srRcpt.unFrm.srDet.srMid.szTotalTipAmt, pobTran->srBRec.szTime);
    vdFormatTime(srRcpt.unFrm.srDet.srMid.szTotalTipAmt);
#endif /*CITI_IND*/

    vdSetTranStatus(pobTran);
}

/*********************************************************************************************
* @func int | inCPACSummaryReportOperation |
*
*       Print Totals Report Operation.
*
* @parm TRANSACTION_OBJECT * | pobTran |
*
* @rdesc return values.
* @flag int    |  VS_SUCCESS
* @flag int    |  VS_ERR
* @end

**********************************************************************************************/

int inCPACSummaryReportOperation(TRANSACTION_OBJECT* pobTran) {
#ifndef IMAM_REMOVE
    /*    pdebug(("--inSummaryReportOperation--"));*/
#if CITI_PHIL
    lnCPACMiddleCondition = lnMiddleCondition;
#endif /* CITI_PHIL */

    //leo_nosourcesafe
#ifdef CITI_IND
    lnCPACMiddleCondition = lnMiddleCondition;
#endif /* CITI_IND */

    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }
    //if (!fGetEnablePrinter())
    //    return(VS_SUCCESS);

    inGetReport1Template();
    return(inCPACPrintSummaryReport(&obPrinter, pobTran));
#endif //IMAM_REMOVE
	return VS_SUCCESS;
}

/*********************************************************************************************
* @func int | inCPACPrintSummaryReport |
*
*       Print Totals Report.
*
* @parm PRINTER_OBJECT * | pobPrinter |
* @parm TRANSACTION_OBJECT * | pobTran |
*
* @rdesc return values.
* @flag int    |  VS_SUCCESS
* @flag int    |  VS_ERR
* @end

**********************************************************************************************/

int inCPACPrintSummaryReport(PRINTER_OBJECT* pobPrinter,TRANSACTION_OBJECT* pobTran) {
    char szDate[DATE_SIZE + 1];
    int inStart,
    inStop,
    inNumberOfMerchants,
    inMerch = 0;
    int inHostIndex;
    int inReportTop = VS_TRUE;
    //    CBT_ACCUM_VALUES srAccum; CPAC_LINT_REMOVED

#ifdef DOWNLOAD_MULTIPLE_LOGO
    inMultipleDownloadLogo(0);
#endif

    /*     if ( fChkAllHostBatches(pobTran) )
        {
            vdDisplayMessageFromFile( BATCH_EMPTY_MSG, WARNING_MSG);
            return(VS_SUCCESS);
        }  Devil */
    if (inGetHostTranCnt(pobTran) < 1) {
        vdDisplayMessageFromFile(BATCH_EMPTY_MSG, WARNING_MSG);
        //  return(BATCH_EMPTY_MSG);
        vdSGErrorMessage(0L);
        return (VS_SUCCESS);
    }

    inNumberOfMerchants = inSelectOneAllMID(pobTran, fGetMultiMerchPrompt());//1.4
    inHostIndex = inGetHostHandle(); //LENIN
    vdSetMerchantNum(inGlobalMerchantHandle);
    if (inNumberOfMerchants == inGetMITTotRecs()) {
        inStart = 1;
        inStop = inGetMITTotRecs();
    } else if (inNumberOfMerchants == 1) {
        inStart = inGetMerchantNum();
        inStop = inGetMerchantNum();
    } else {
        inStart = 1;
        inStop = 0;
    }
    inMerch = inGetMerchantNum();;
    //for (inMerch = inStart; inMerch <= inStop; inMerch++)
    //{            // Commented by Lenin to support multi- merchant
    if (inLoadMITRec(inMerch - 1) != VS_SUCCESS)
        return(VS_ERR);

    /* Get the total number of records in the batch */
    if (inGetDCBatchRecCnt(pobTran) == 0) {
        vdDisplayMessageFromFile(BATCH_EMPTY_MSG, WARNING_MSG);
        vdCloseDCBatch(pobTran); /* bb1 */
        /* loop back for next merchant */
        // continue; LENIN
        return (VS_ERR);
    }
    vdCloseDCBatch(pobTran); /* bb1 */

    if (fGetEnablePrinter())
        vdDisplayMessageFromFile(PRINTING_MSG, STATUS_MSG);

    if (inGGCode() == SETTLE) {
        vdGetDate(szDate, MMDDYY);
        strlcpy(pobTran->szSettDate, szDate, DATE_SIZE);
        //leo_nosourcesafe
#ifdef CITI_IND
        vdGetDate(srRcpt.szDate, YYMMDD);
        vdFormatCITIDate(srRcpt.szDate);
#endif /*CITI_IND*/
    }

    //LENIN    for (inHostIndex = 0; inHostIndex < MAX_HOSTS; inHostIndex++)
    // LENIN {
    // LENIN        vdSetCDTHostIndex (inHostIndex);

    if (inLoadDefaultHost(inHostIndex) != VS_SUCCESS) //1.4
        return (VS_ERR);

    if (inLoadDefaultCurrency(pobTran) != VS_SUCCESS)
        return (VS_ERR);

    /*          inCBTGetAccum (pobTran, 1, srAccum, 1);  removed to remove the batch error message */
    /* Only print the report for independent host */

    //Kelvin_F2 --- start: fix the bug for if single merchant, double header...
    // vdMakeReportHeader(pobTran);//saritha
    // inPrintReceiptHeader(pobTran); //saritha
    //Kelvin_F2 --- end: fix the bug for if single merchant, double header...
    if (fIsIndependentBatch(inGetHostHandle()))  // 1.4

        /*            if (srHDTRec.shHostGroupRef == srHDTRec.inBatchIndex) sad_14 */ {
        /* Print the overall totals */
        //kelvin_f2 Bug fix for handle decrease 29apr2002
        //inCPACPrintSummaryMiddle (pobPrinter, pobTran, &inReportTop, inNumberOfMerchants); /* mb1 */
        if (inCPACPrintSummaryMiddle(pobPrinter, pobTran, &inReportTop, inNumberOfMerchants) != VS_SUCCESS)
            return (VS_ERR);
    }
    //LENIN     } /* host loop */
    /* Print FORM_FEED  */
    if (inPrintLines(pobPrinter, CPAC_END_OF_REPORT_START, CPAC_END_OF_REPORT_END, NO_BL_LINE, 0x80000000) != VS_SUCCESS)
        return(VS_ERR);
    if (inGGCode() != SETTLE) {
        if (inPrintLines(pobPrinter, 198, 198, NO_BL_LINE, 0L) != VS_SUCCESS)
            return(VS_ERR);
    }

    //}  commented by Lenin to support multi host  /* merchant loop */

    return(VS_SUCCESS);
}


/*********************************************************************************************
* @func void | vdCPACSetSummaryHeaderCondition |
*
*       Set conditions for Totals Report.
*
* @parm int  | inReportTop |
* @parm int  | inGrandTotals |
*
* @rdesc return values.
* @flag int    |  VS_SUCCESS
* @flag int    |  VS_ERR
* @end

**********************************************************************************************/

void vdCPACSetSummaryHeaderCondition(int inReportTop,TRANSACTION_OBJECT* pobTran,int inGrandTotals) {
    if (inGetPrinterType() == NOPRINTER || !fGetEnablePrinter())
        return;

    lnHeaderCondition = formater_set_flags(inReportTop, (inReportTop && fGetDemoMode() == VS_TRUE), (inGetMITTotRecs() > 1),
                        0,

                        (inGGCode() == SETTLE),
                        0,
                        0,
                        0,

                        0,
                        0,
                        0,
                        0,

                        0,
                        0,
                        0,
                        0,

                        (inGetTipProcessing() == TIP_OFF && !(fGetCashBack())),
                        (inGetTipProcessing() > TIP_OFF && !(fGetCashBack())),
                        (inGetTipProcessing() == TIP_OFF && fGetCashBack()),
                        (inGetTipProcessing() > TIP_OFF && fGetCashBack()),

                        0,
                        0,
                        0,
                        0,

                        0,
                        0,
                        0,
                        0,

                        0,
                        0,
                        0,
                        0, -1);
}

/*********************************************************************************************
* @func void | vdCPACSetSummaryMiddleCondition |
*
*       Set conditions for Totals Report.
*
* @rdesc VOID
* @end
**********************************************************************************************/

void vdCPACSetSummaryMiddleCondition() {
    lnMiddleCondition = formater_set_flags(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (inGetTipProcessing() > TIP_OFF),
                (inGetTipProcessing() > TIP_OFF && !(fGetCashBack())),
                (inGetTipProcessing() == TIP_OFF && fGetCashBack()),
                (inGetTipProcessing() > TIP_OFF && fGetCashBack()),

                0,
                0,
                0,
                0,

                0,
                0,
                0,
                0,

                0,
                0,
                0,
                0, -1);
}

/*********************************************************************************************
* @func void | vdCPACSetSummaryBottomCondition |
*
*       Set conditions for Totals Report.
*
* @parm TRANSACTION_OBJECT * | pobTran |
* @parm int  | inFormFeed |
* @parm CARD_TOTS_REC * | srTots |
*
* @rdesc VOID
* @end
**********************************************************************************************/

void vdCPACSetSummaryBottomCondition(TRANSACTION_OBJECT* pobTran,int inFormFeed,CARD_TOTS_REC* srTots) {
    lnBottomCondition = formater_set_flags((inFormFeed), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (fGetTaxProc() || srTots->dbTaxAmt > 0.00),
                0,
                0,
                0,

                0,
                0,
                0,
                0,

                0,
                0,
                0,
                0,

                (inGetTipProcessing() > TIP_OFF),
                (fGetCashBack()),
                inGetSurCharge(),
                0, -1);
}

/*********************************************************************************************
* @func int | inCPACPrintSummaryMiddle |
*
*       Browse the Acummulators and print items with totals.
*
* @parm PRINTER_OBJECT * | pobPrinter |
* @parm TRANSACTION_OBJECT * | pobTran |
*
* @rdesc return values.
* @flag int    |  VS_SUCCESS
* @flag int    |  VS_ERR
* @end

**********************************************************************************************/


int inCPACPrintSummaryMiddle(PRINTER_OBJECT* pobPrinter,TRANSACTION_OBJECT* pobTran,int* pinReportTop,int inNumberOfMerchants) {
    //    int inHostIdx; CPAC_LINT_REMOVED
    int inNewHost;
    CARD_TOTS_REC srGrandTots;

#ifdef CITI_IND
    RCPT_FIELDS srTempRcpt;
#endif /* CITI_IND CPAC_LINT */

    /*   Saritha_b1...........Start............Reprint Settlement Report  */

    // #ifdef TLFB   (Made this feature as the part of CPAC Base Application)
    char szSFileName[FILENAME_SIZE + 1];
    int inRecCnt = 1;
    // #endif /*  TLFB  */  (Made this feature as the part of CPAC Base Application)

    /*   Saritha_b1............End.............Reprint Settlement Report  */

    int inIssuer = 0;
    int inIssuerCnt = 0;
    int inGrandIssuerCnt = 0;
    int inRetVal = 0;
    long lnRecNum = 0L;
    int inNegPos;
    char szCurSym[CUR_SYMBOL_SIZE + 1];
    long lnCount = 0L,
    lnAmount = 0L,
    lnTip = 0L,
    lnTotal = 0L,
    lnTax = 0L,
    lnSurCharge = 0L,
    lnCashBack = 0L;
    long lnDebitCount = 0L,
    lnCreditCount = 0L,
    lnAdjustCount = 0L,
    lnNetCount = 0L;
    long lnDebitAmount = 0L,
    lnCreditAmount = 0L,
    lnAdjustAmount = 0L,
    lnNetAmount = 0L;
    long lnSaleCount = 0L,
    lnRefundCount = 0L,
    lnVoidSaleCount = 0L,
    lnVoidRefundCount = 0L,
    lnTotalCount = 0L;
    double dbSaleAmount = 0.0,
    dbRefundAmount = 0.0,
    dbVoidSaleAmount = 0.0,
    dbVoidRefundAmount = 0.0,
    dbTotalAmount = 0.0;
    unsigned char ucIITTempRec[SIZE_IIT_REC + 1];


    double dbGrandSaleAmount = 0.0,
    dbGrandRefundAmount = 0.0,
    dbGrandVoidSaleAmount = 0.0,
    dbGrandVoidRefundAmount = 0.0,
    dbGrandTotalAmount = 0.0;
    long lnGrandSaleCount = 0L,
    lnGrandRefundCount = 0L,
    lnGrandVoidSaleCount = 0L,
    lnGrandVoidRefundCount = 0L,
    lnGrandTotalCount = 0L;

    long lnOfflineCount = 0L,
    lnGrandOfflineCount = 0L;
    double dbOfflineAmount = 0.0,
    dbGrandOfflineAmount = 0.0;
    double dbTipAmount = 0.0,
    dbGrandTipAmount = 0.0;

    char szFileName[FILENAME_SIZE + 1];
    DB_FILE srDBFPtr;
    ACCUM_REC srAccumRec;
    ACCUM_KEY srAccumKey;
    ACCUM_SKEY srAccumSKey;
    int inKeyIdx = 0;
    int inResult = 0;

    long lnAdjustNum = 0;

    FHANDLE hFHandle;
    ACCUM_SHIFT srASI;
    /* LENIN CPAC #if TBD_CPAC */
    //  IIT_REC srCPACIITRec; cpac_2.2a
    /* LENIN CPAC #endif  TBD_CPAC */

    //memset(&srRcpt, 0, sizeof(RCPT_FIELDS)); //leo_nov1400
    memset((char *) &srGrandTots, 0x00, (SIZE_CARD_TOTS_REC));
    /*  {
            srGrandTots.inTotalCnt = 0;
            srGrandTots.lnTotalAmt = 0L;
            srGrandTots.lnSaleAmt  = 0L;
            srGrandTots.lnTipAmt   = 0L;
            srGrandTots.lnTaxAmt   = 0L;
            srGrandTots.lnSurCharge   = 0L;
            srGrandTots.lnCashBack   = 0L;
           }
    */
    vdGetAccumFName(szFileName);
#ifdef CITI_PHIL
    if (inGGCode() == SETTLE) {
        if (lnCPACMiddleCondition & 0x02000000)
            lnAdjustNum = 1L;
    }
#endif /* CITI_PHIL */
    //leo_nosourcesafe
#ifdef CITI_IND
    if (inGGCode() == SETTLE) {
        if (lnCPACMiddleCondition & 0x02000000)
            lnAdjustNum = 1L;
    }
#endif /* CITI_IND */
    if (inOpenAccum(&srDBFPtr, szFileName) != VS_SUCCESS) {

        vdSGErrorMessage(BATCH_ERR_MSG);
        return(VS_ERR);
    }

    vdCPACSetSummaryMiddleCondition();

    /*  Read ASI File to use for determining if issuer accumulator has been updated */


    vdGetASIFName(szFileName);
    if ((hFHandle = open(szFileName, O_RDWR)) < 0) {
        if ((hFHandle = open(szFileName, O_CREAT | O_RDWR)) < 0)
            return(VS_ERR);

        memset((char *) &srASI, 0x00, SIZE_ACCUM_SHIFT);
    } else
        inResult = read(hFHandle, (char *) &srASI, SIZE_ACCUM_SHIFT);

    close(hFHandle);

    srAccumSKey.compare_func = inAccumCompFn;
    inNewHost = VS_TRUE;
    inIssuerCnt = 0;

    for (inIssuer = 0; inIssuer < TOTAL_ISSUERS; inIssuer++) {
#if 0
    if (srASI.srIssuer.fActiveAccum[inIssuer] == '\0')
        continue;

inGetIssuerRecord(inIssuer);
#ifdef CITI_IND
memcpy(&srTempRcpt.unFrm.srSubTotal.srTerm, &srRcpt.unFrm.srSubTotal.srTerm, sizeof(srRcpt.unFrm.srSubTotal.srTerm)); //leo_nov1300
#endif
strlcpy(srRcpt.unFrm.srSummary.srMid.szCType, srCPACIITRec.szIssuerLabel, CLABEL_SIZE);
#endif /* 0 */

        if ((inLoadIITRecFromStruct(inIssuer, ucIITTempRec)) == VS_ERR) {
            inCloseAccum(&srDBFPtr);
            vdSGErrorMessage(IIT_ERR_MSG21);
            return(VS_ERR);
        }

        if (srASI.srIssuer.fActiveAccum[inGetIssuerNumberFromStruct(ucIITTempRec)] == '\0')
            continue;
#ifdef CITI_IND
        memcpy(&srTempRcpt.unFrm.srSubTotal.srTerm, &srRcpt.unFrm.srSubTotal.srTerm, sizeof(srRcpt.unFrm.srSubTotal.srTerm)); //leo_nov1300

#endif
        strlcpy(srRcpt.unFrm.srSummary.srMid.szCType, szGetIssuerLabelFromStruct(ucIITTempRec), CLABEL_SIZE);


        //    srAccumKey.inIssuerNumber = inIssuer;
        //    srAccumSKey.accumKey.inIssuerNumber = inIssuer;
        srAccumKey.inIssuerNumber = inGetIssuerNumberFromStruct(ucIITTempRec);
        srAccumSKey.accumKey.inIssuerNumber = inGetIssuerNumberFromStruct(ucIITTempRec);
        /* If record does not exist then go to next issuer */
        inRetVal = inKeyReadAccum(&srDBFPtr, &srAccumRec, &srAccumKey, &srAccumSKey, &lnRecNum);
        if (inRetVal == VS_SUCCESS) {
            long2str(srRcpt.szBatchNum, (lnGetBatchNum() - lnAdjustNum));
            if (inNewHost) {
                if (*pinReportTop == VS_TRUE) {
                    vdMakeReportHeader(pobTran);
                    if (inGetMITTotRecs() == 1 || inNumberOfMerchants == 1) {
                        long2str(srRcpt.szBatchNum, (lnGetBatchNum() - lnAdjustNum));
                        //sprintf(srRcpt.szBatchNum, "%03ld", lnGetBatchNum());
                        //  strcpy (srRcpt.szBatchNum,pobTran->szBatchNum);/* Lenin */

                        inPrintReceiptHeader(pobTran);
                    } else {
                        long2str(srRcpt.szBatchNum, (lnGetBatchNum() - lnAdjustNum));
                        //sprintf(srRcpt.szBatchNum, "%03ld", lnGetBatchNum());
                        // if (inPrintLines(pobPrinter, REPORT_HEADER_START, REPORT_HEADER_END, NO_BL_LINE, lnHeaderCondition) != VS_SUCCESS)
                        //     return(VS_ERR);
                        //Kelvin_F2 --- start: fix the bug for if single merchant, double header...
                        //Kelvin_F2 Bug fix for handle decrease 29apr2002
                        //inPrintReceiptHeader(pobTran);
                        if (inPrintReceiptHeader(pobTran) != VS_SUCCESS) {
                            inCloseAccum(&srDBFPtr);
                            return(VS_ERR);
                        }
                        //Kelvin_F2 --- end: fix the bug for if single merchant, double header...
                    }
                }

                inNewHost = VS_FALSE;
                /* Header condition should not print report title except at top of report */
                vdCPACSetSummaryHeaderCondition(*pinReportTop, pobTran, VS_FALSE);
                *pinReportTop = VS_FALSE;

                strlcpy(srRcpt.szMerchantName, szGetMerchantText(), sizeof(srRcpt.szMerchantName));
                strlcpy(srRcpt.szHostName, szGetHostName(), sizeof(srRcpt.szHostName));
#ifdef CITI_PHIL
                //Kelvin_F2 --- start: no need to mask TID
#ifdef MASK_TID_AND_MID
                vdMaskCitiMTID();
#endif
                //Kelvin_F2 --- end: no need to mask TID
#endif /* CITI_PHIL */
                //leo_nosourcesafe
#ifdef CITI_IND
                vdGetDate(srRcpt.szDate, YYMMDD);
                vdFormatCITIDate(srRcpt.szDate);
#endif /*CITI_IND*/
				vdImamReformatDate(srRcpt.szDate);
                pad(srRcpt.szBatchNum, srRcpt.szBatchNum, '0', inGetBatchNumSize(), RIGHT); // Lenin 1.4
                if (inPrintLines(pobPrinter, CPAC_SUMMARY_TOP_START, CPAC_SUMMARY_TOP_END, NO_BL_LINE, lnHeaderCondition) != VS_SUCCESS) {
                    //Kelvin_F2 Bug fix for handle decrease 29apr2002
                    //    return(VS_ERR);
                    inCloseAccum(&srDBFPtr);
                    return(VS_ERR);
                }


                /*Saritha_b1.............Start...........Amex SOC Printing */
#ifdef AMEX_SOC
                if (inGGOpCode() == SETTLE_OPERATION) {
                    strcpy(srRcpt.unFrm.srReceipt.szGenBuf2, (char *) srISO.pszField62);
                    if (strcmp(szGetHostFileName(), "AXAP") == 0) {
                        if (inPrintLines(&obPrinter, AMEX_SOC_PRINT_START, AMEX_SOC_PRINT_END, NO_BL_LINE, 4L) != VS_SUCCESS) {
                            //Kelvin_F2 Bug fix for handle decrease 29apr2002
                            //    return(VS_ERR);
                            inCloseAccum(&srDBFPtr);
                            return(VS_ERR);
				}
        	}
		#ifndef ICICI
               /*venu soc fix*/
		else
        	{
           		// If it is not AXAP, depend on condition line set in TPL file.
           		if (inPrintLines(&obPrinter, AMEX_SOC_PRINT_START,AMEX_SOC_PRINT_END, NO_BL_LINE, 2L) != VS_SUCCESS)
                {           //Kelvin_F2 Bug fix for handle decrease 29apr2002
					        //    return(VS_ERR);
							inCloseAccum(&srDBFPtr);
							return(VS_ERR);
				}
        	}
        	#endif  /* ICICI  */
                }

#endif  /*   AMEX_SOC */

                /* Saritha_b1.............End...........Amex SOC Printing */

                /*Saritha_b1.............Start...........Reprint Settlement Report */

                // #ifdef TLFB  (Made this feature as the part of CPAC Base Application)

                if (inGGCode() == SETTLE) {
                    vdGetReprintSettleFileName(szSFileName, CPAC_HEADER);

                    if (inDBFileExists(szSFileName) == VS_SUCCESS)
                        inDBRemoveFile(szSFileName);

                    if (inDBFileExists(szSFileName) != VS_SUCCESS)
                        if (inDBCreateFile(szSFileName, sizeof(srCPACSettleHeader)) != VS_SUCCESS)
                            ACTIVITY_LOG("HDR Fopen failed");//return(VS_ERROR);

                    memset(&srCPACSettleHeader, 0x00, sizeof(srCPACSettleHeader));

                    strcpy(srCPACSettleHeader.szDate, srRcpt.szDate);
                    strcpy(srCPACSettleHeader.szTime, srRcpt.szTime);
		#if 0  // imam 
		  inSetCPACMaskTIDMID(pobTran,srRcpt.szTermId,srRcpt.szMerchantId);
		#endif			
		    strcpy(srCPACSettleHeader.szMID, srRcpt.szMerchantId);
                    strcpy(srCPACSettleHeader.szTID, srRcpt.szTermId);
                    strcpy(srCPACSettleHeader.szBatchNum, srRcpt.szBatchNum);
                    strcpy(srCPACSettleHeader.szHostName, srRcpt.szHostName);
                    srCPACSettleHeader.lnHeaderCond = lnHeaderCondition;

#ifdef AMEX_SOC
                    strcpy(srCPACSettleHeader.szSOC, srRcpt.unFrm.srReceipt.szGenBuf2);
#endif /*  AMEX_SOC */

                    if (inDBWriteRecord(szSFileName, 1, (unsigned char *) &srCPACSettleHeader) < 0)
                        ACTIVITY_LOG("Hdr storage failed");
                }
                // #endif   /* TLFB */   (Made this feature as the part of CPAC Base Application)
                /*Saritha_b1..............End............Reprint Settlement Report */
            }
            /*  Use totals from record */


            lnSaleCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].lnCount[SALE_TRAN] ;

            lnRefundCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[REFUND_TRAN] + srAccumRec.srTotals[DEBIT_CARD].lnCount[REFUND_TRAN];

            lnVoidSaleCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[VOID_SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].lnCount[VOID_SALE_TRAN];

            lnVoidRefundCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[VOID_REFUND_TRAN] + srAccumRec.srTotals[DEBIT_CARD].lnCount[VOID_REFUND_TRAN];


            lnTotalCount = lnSaleCount + lnRefundCount + lnVoidSaleCount + lnVoidRefundCount;

            lnOfflineCount = srAccumRec.srTotals[CREDIT_CARD].dbCustom1[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbCustom1[SALE_TRAN] ;



            /* lnCreditCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[SALE_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnCount[SALE_TRAN] ;
            lnDebitCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[REFUND_TRAN]                          + srAccumRec.srTotals[DEBIT_CARD].lnCount[REFUND_TRAN];
              lnCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[SALE_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnCount[SALE_TRAN] +
                        srAccumRec.srTotals[CREDIT_CARD].lnCount[REFUND_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnCount[REFUND_TRAN];
            */


            dbSaleAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbAmount[SALE_TRAN];
            dbRefundAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[REFUND_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbAmount[REFUND_TRAN];

            dbVoidSaleAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[VOID_SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbAmount[VOID_SALE_TRAN];

            dbVoidRefundAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[VOID_REFUND_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbAmount[VOID_REFUND_TRAN];
            dbTotalAmount = dbSaleAmount - dbRefundAmount;
            //-lnVoidSaleAmount;

            dbOfflineAmount = srAccumRec.srTotals[CREDIT_CARD].dbCustom2[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbCustom2[SALE_TRAN];
            dbTipAmount = srAccumRec.srTotals[CREDIT_CARD].dbTip[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbTip[SALE_TRAN];
#ifdef CITI_PHIL
            if (lnSaleCount >= lnOfflineCount) {
                lnSaleCount -= lnOfflineCount;
                dbSaleAmount -= dbOfflineAmount;
            }
#ifdef  SHELL_FLEET
            lnSaleCount += lnOfflineCount;
            dbSaleAmount += dbOfflineAmount;

#endif /* SHELL_FLEET */
#endif /* CITI_PHIL */

            /* Set print line */

            sprintf(srRcpt.unFrm.srSummary.srMid.szCreditCount, SUBSTITUTE_LD, lnSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szDebitCount, SUBSTITUTE_LD, lnRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustCount, SUBSTITUTE_LD, lnVoidSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szReversalCount, SUBSTITUTE_LD, lnVoidRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szNetCount, SUBSTITUTE_LD, lnTotalCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szShiftNumber, SUBSTITUTE_LD, lnOfflineCount);

            /* Total Amount */
            vdDb2Str(dbSaleAmount, srRcpt.unFrm.srSummary.srMid.szCreditTotal);
            vdDb2Str(dbRefundAmount, srRcpt.unFrm.srSummary.srMid.szDebitTotal);
            vdDb2Str(dbVoidSaleAmount, srRcpt.unFrm.srSummary.srMid.szAdjustTotal);

            vdDb2Str(dbVoidRefundAmount, srRcpt.unFrm.srSummary.srMid.szReversalTotal);
            vdDb2Str(dbTotalAmount, srRcpt.unFrm.srSummary.srMid.szNetTotal);
            vdDb2Str(dbOfflineAmount, srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
            vdDb2Str(dbTipAmount, srRcpt.unFrm.srSummary.srMid.szCashBackTotal);
            //sprintf(srRcpt.unFrm.srSummary.srMid.szCreditTotal, SUBSTITUTE_LD, lnSaleAmount);
            //  sprintf(srRcpt.unFrm.srSummary.srMid.szDebitTotal, SUBSTITUTE_LD, lnRefundAmount);
            //  sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, SUBSTITUTE_LD, lnVoidSaleAmount);
            //   sprintf(srRcpt.unFrm.srSummary.srMid.szReversalTotal, SUBSTITUTE_LD, lnVoidRefundAmount);
            //   sprintf(srRcpt.unFrm.srSummary.srMid.szNetTotal, SUBSTITUTE_LD, lnTotalAmount);
            //  sprintf(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, SUBSTITUTE_LD, lnOfflineAmount);
            /* will put dollar sign in front */
            /* vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCreditTotal);  */
            //vdPutDecPoint(srRcpt.unFrm.srSummary.srMid.szCreditTotal);
            /* Sale Amount (Base Amount)*/
            /* LENIN  sprintf(srRcpt.unFrm.srSummary.srMid.szDebitTotal, SUBSTITUTE_LD,
                 (lnAmount - lnTip - lnTax - lnSurCharge - lnCashBack)); */
            //vdPutDecPoint(srRcpt.unFrm.srSummary.srMid.szDebitTotal);
            /*Tip Amount */
            //sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, SUBSTITUTE_LD, lnTip);
            //vdPutDecPoint(srRcpt.unFrm.srSummary.srMid.szAdjustTotal);
            /*CashBack Amount */
            //sprintf(srRcpt.unFrm.srSummary.srMid.szCashBackTotal, SUBSTITUTE_LD, lnCashBack);
            //vdPutDecPoint(srRcpt.unFrm.srSummary.srMid.szCashBackTotal);
            // if (inPrintLines(pobPrinter, SUMMARY_TOP_START, SUMMARY_TOP_END, NO_BL_LINE, lnHeaderCondition) != VS_SUCCESS)
            //       return(VS_ERR);

            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCreditTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szDebitTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szReversalTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szNetTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCashBackTotal, VS_TRUE);
            /*  KK removed these lines to avoid two '-' sumbols from the total.

                        if ((lnSaleAmount - lnRefundAmount)< -999999999L) {

                            vdGetCSTCurSymbol(szCurSym);
                            inNegPos=strlen(szCurSym);
                            srRcpt.unFrm.srSummary.srMid.szNetTotal[inNegPos]='-';

                         }

            */
            // inGetIssuerRecord(inIssuer, &srCPACIITRec);
            //strlcpy(srRcpt.unFrm.srSummary.srMid.szCType, srIDTRec.szIssuerLabel, CLABEL_SIZE);
            //vdGetIssuerLabel(srRcpt.unFrm.srSummary.srMid.szCType);

			{//LIEM Add to correct the calculation
				unsigned long lnImamTotal;
				lnImamTotal = atol(srRcpt.unFrm.srSummary.srMid.szNetCount) 
								- atol(srRcpt.unFrm.srSummary.srMid.szAdjustCount) 
								- atol(srRcpt.unFrm.srSummary.srMid.szReversalCount);
				sprintf(srRcpt.unFrm.srSummary.srMid.szNetCount, SUBSTITUTE_LD, lnImamTotal);
			}

if(inGetTipProcessing() ==1)
{
            if (inPrintLines(pobPrinter, CPAC_SUMMARY_MIDDLE_START, CPAC_SUMMARY_MIDDLE_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
            {           //Kelvin_F2 Bug fix for handle decrease 29apr2002
                //    return(VS_ERR);
                inCloseAccum(&srDBFPtr);
                return(VS_ERR);
            }
}
else
{

		 if (inPrintLines(pobPrinter, CPAC_SUMMARY_MIDDLE_START, 180, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
					{			//Kelvin_F2 Bug fix for handle decrease 29apr2002
									//	  return(VS_ERR);
									inCloseAccum(&srDBFPtr);
									return(VS_ERR);
					}
		}

            /*Saritha_b1.............Start...........Reprint Settlement Report */
            // #ifdef TLFB   (Made this feature as the part of CPAC Base Application)

            if (inGGCode() == SETTLE) {
                vdGetReprintSettleFileName(szSFileName, CPAC_BODY);

                // if (inDBFileExists(szSFileName) == VS_SUCCESS)  By kelvin_f2 multi_issuer
                if ((inDBFileExists(szSFileName) == VS_SUCCESS) && (inRecCnt == 1))
                    inDBRemoveFile(szSFileName);


                if (inDBFileExists(szSFileName) != VS_SUCCESS)
                    if (inDBCreateFile(szSFileName, sizeof(srCPACSettleMiddle)) != VS_SUCCESS)
                        ACTIVITY_LOG("Bdy Fopen failed");//return(VS_ERROR);

                memset(&srCPACSettleMiddle, 0x00, sizeof(srCPACSettleMiddle));

                strcpy(srCPACSettleMiddle.szCardName, srRcpt.unFrm.srSummary.srMid.szCType);
                strcpy(srCPACSettleMiddle.szCreditCnt, srRcpt.unFrm.srSummary.srMid.szCreditCount);
                strcpy(srCPACSettleMiddle.szCreditTot, srRcpt.unFrm.srSummary.srMid.szCreditTotal);
                strcpy(srCPACSettleMiddle.szDebitCnt, srRcpt.unFrm.srSummary.srMid.szDebitCount);
                strcpy(srCPACSettleMiddle.szDebitTot, srRcpt.unFrm.srSummary.srMid.szDebitTotal);
                strcpy(srCPACSettleMiddle.szShiftNum, srRcpt.unFrm.srSummary.srMid.szShiftNumber);
                strcpy(srCPACSettleMiddle.szSurCharge, srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
                strcpy(srCPACSettleMiddle.szAdjCnt, srRcpt.unFrm.srSummary.srMid.szAdjustCount);
                strcpy(srCPACSettleMiddle.szAdjTot, srRcpt.unFrm.srSummary.srMid.szAdjustTotal);
                strcpy(srCPACSettleMiddle.szReversalCnt, srRcpt.unFrm.srSummary.srMid.szReversalCount);
                strcpy(srCPACSettleMiddle.szReversalTot, srRcpt.unFrm.srSummary.srMid.szReversalTotal);
                strcpy(srCPACSettleMiddle.szNetCnt, srRcpt.unFrm.srSummary.srMid.szNetCount);
                strcpy(srCPACSettleMiddle.szNetTot, srRcpt.unFrm.srSummary.srMid.szNetTotal);
                srCPACSettleMiddle.lnMiddleCond = lnMiddleCondition;

                if (inDBWriteRecord(szSFileName, inRecCnt, (unsigned char *) &srCPACSettleMiddle) < 0)
                    ACTIVITY_LOG("Settle Middle Failed");

                inRecCnt++;
            }
            // #endif   /* TLFB */  (Made this feature as the part of CPAC Base Application)
            /*Saritha_b1..............End............Reprint Settlement Report
            //   if (act_kbd_pending_test(KEY_CANCEL)) (Saritha_b1 commented )
            //   return(VS_ESCAPE);     (Saritha_b1 commented )

            Accumulate totals */


            /*            srGrandTots.inTotalCnt += (int)(lnSaleCount+lnRefundCount+lnVoidSaleCount+lnVoidRefundCount);
                        srGrandTots.lnTotalAmt += dbTotalAmount;
                        srGrandTots.lnSaleAmt  += (dbSaleAmount);
                        srGrandTots.lnTipAmt   += dbTip;
                        srGrandTots.lnTaxAmt    += dbTax;
                        srGrandTots.lnSurCharge += dbSurCharge;
                        srGrandTots.lnCashBack  += dbCashBack;
            */

            lnGrandTotalCount += (int) (lnSaleCount + lnRefundCount + lnVoidSaleCount + lnVoidRefundCount + lnOfflineCount);

            lnGrandSaleCount += lnSaleCount;
            lnGrandRefundCount += lnRefundCount;
            lnGrandVoidSaleCount += lnVoidSaleCount;
            lnGrandVoidRefundCount += lnVoidRefundCount;
            lnGrandOfflineCount += lnOfflineCount;

            dbGrandSaleAmount += dbSaleAmount;
            dbGrandRefundAmount += dbRefundAmount;
            dbGrandVoidSaleAmount += dbVoidSaleAmount;
            dbGrandVoidRefundAmount += dbVoidRefundAmount;
            dbGrandOfflineAmount += dbOfflineAmount;
            dbGrandTipAmount += dbTipAmount;


            //( lnSaleCount+lnRefundCount+lnVoidSaleCount+lnVoidRefundCount);


            inIssuerCnt++;
            if (inIssuerCnt > inGrandIssuerCnt)
                inGrandIssuerCnt = inIssuerCnt;
#ifdef CITI_IND

            memcpy(&srRcpt.unFrm.srSubTotal.srTerm, &srTempRcpt.unFrm.srSubTotal.srTerm, sizeof(srRcpt.unFrm.srSubTotal.srTerm));

#endif
        }
    }
    inCloseAccum(&srDBFPtr);

    /* Print Grand Totals if more than one issuer */
    if (inIssuerCnt > 0) {  //LIEM : Originally only print if "> 1"
        if (inGrandIssuerCnt > 0) { //LIEM : Originally only print if "> 1"
#if 0 /* LENIN */
    /* Set print line */
    sprintf(srRcpt.unFrm.srSummary.srMid.szCreditCount, SUBSTITUTE_D,
        srGrandTots/*[TOTAL_ISSUERS]*/.inTotalCnt);
    /* Total Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szCreditTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnTotalAmt);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCreditTotal);
    /* Sale Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szDebitTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnSaleAmt);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szDebitTotal);
    /*Tip Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnTipAmt);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szAdjustTotal);
    /*Tax Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szTaxTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnTaxAmt);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szTaxTotal);
    /*Surcharge Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnSurCharge);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
    /*CashBack Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szCashBackTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnCashBack);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCashBackTotal);
    /* Send VS_TRUE so FORM_FEED will print */
    #endif /* 0 */
#ifdef CITI_IND
            memcpy(&srTempRcpt.unFrm.srSubTotal.srTerm, &srRcpt.unFrm.srSubTotal.srTerm, sizeof(srRcpt.unFrm.srSubTotal.srTerm)); //leo_nov1300

#endif
            //            lnGrandTotalAmount=lnGrandSaleAmount-lnGrandRefundAmount+lnGrandVoidRefundAmount-lnGrandVoidSaleAmount;
            dbGrandTotalAmount = dbGrandSaleAmount - dbGrandRefundAmount + dbGrandOfflineAmount;

#ifdef CITI_IND

            dbGrandTotalAmount = dbGrandSaleAmount - dbGrandRefundAmount;

#endif /*CITI_IND*/
            //+lnGrandVoidRefundAmount-lnGrandVoidSaleAmount;
            //if (lnGrandSaleCount >= lnGrandOfflineCount){
            //  lnGrandSaleCount-=lnGrandOfflineCount;
            //  lnGrandSaleAmount-=lnGrandOfflineAmount;
            //}




            sprintf(srRcpt.unFrm.srSummary.srMid.szCreditCount, SUBSTITUTE_LD, lnGrandSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szDebitCount, SUBSTITUTE_LD, lnGrandRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustCount, SUBSTITUTE_LD, lnGrandVoidSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szReversalCount, SUBSTITUTE_LD, lnGrandVoidRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szNetCount, SUBSTITUTE_LD, lnGrandTotalCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szShiftNumber, SUBSTITUTE_LD, lnGrandOfflineCount);



            vdDb2Str(dbGrandSaleAmount, srRcpt.unFrm.srSummary.srMid.szCreditTotal);
            vdDb2Str(dbGrandRefundAmount, srRcpt.unFrm.srSummary.srMid.szDebitTotal);
            vdDb2Str(dbGrandVoidSaleAmount, srRcpt.unFrm.srSummary.srMid.szAdjustTotal);

            vdDb2Str(dbGrandVoidRefundAmount, srRcpt.unFrm.srSummary.srMid.szReversalTotal);
            vdDb2Str(dbGrandTotalAmount, srRcpt.unFrm.srSummary.srMid.szNetTotal);
            vdDb2Str(dbGrandOfflineAmount, srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
            vdDb2Str(dbGrandTipAmount, srRcpt.unFrm.srSummary.srMid.szCashBackTotal);
            //sprintf(srRcpt.unFrm.srSummary.srMid.szCreditTotal, SUBSTITUTE_LD, lnGrandSaleAmount);
            //  sprintf(srRcpt.unFrm.srSummary.srMid.szDebitTotal, SUBSTITUTE_LD, lnGrandRefundAmount);
            //     sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, SUBSTITUTE_LD, lnGrandVoidSaleAmount);
            // sprintf(srRcpt.unFrm.srSummary.srMid.szReversalTotal, SUBSTITUTE_LD, lnGrandVoidRefundAmount);
            //   sprintf(srRcpt.unFrm.srSummary.srMid.szNetTotal, SUBSTITUTE_LD, lnGrandTotalAmount);
            //sprintf(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, SUBSTITUTE_LD, lnGrandOfflineAmount);


            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCreditTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szDebitTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szReversalTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szNetTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCashBackTotal, VS_TRUE);


            if ((dbGrandSaleAmount - dbGrandRefundAmount) < -99999999999.00) {
                strcpy(szCurSym, szGetCurSymbol());

                inNegPos = strlen(szCurSym);
                srRcpt.unFrm.srSummary.srMid.szNetTotal[inNegPos] = '-';
            }
            vdCPACSetSummaryBottomCondition(pobTran, VS_TRUE, &srGrandTots/*[TOTAL_ISSUERS]*/);
			{//LIEM Add to correct the calculation
				unsigned long lnImamTotal;
				lnImamTotal = atol(srRcpt.unFrm.srSummary.srMid.szNetCount) 
								- atol(srRcpt.unFrm.srSummary.srMid.szAdjustCount) 
								- atol(srRcpt.unFrm.srSummary.srMid.szReversalCount);
				sprintf(srRcpt.unFrm.srSummary.srMid.szNetCount, SUBSTITUTE_LD, lnImamTotal);
			}

            if (inPrintLines(pobPrinter, CPAC_GRANT_TOTAL_LABEL_START, CPAC_GRANT_TOTAL_LABEL_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
                return(VS_ERR);
            //Kelvin_F2 --- start: use CPAC_SUMMARY_BOTTOM_START and CPAC_SUMMARY_BOTTOM_END
            // if (inPrintLines(pobPrinter, SUMMARY_BOTTOM_START, SUMMARY_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
if(inGetTipProcessing() == 1)
{
            if (inPrintLines(pobPrinter, CPAC_SUMMARY_BOTTOM_START, CPAC_SUMMARY_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
                //Kelvin_F2 --- start: use CPAC_SUMMARY_BOTTOM_START and CPAC_SUMMARY_BOTTOM_END
                return(VS_ERR);
}
else
{
	if (inPrintLines(pobPrinter, CPAC_SUMMARY_BOTTOM_START, 194, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
				//Kelvin_F2 --- start: use CPAC_SUMMARY_BOTTOM_START and CPAC_SUMMARY_BOTTOM_END
					return(VS_ERR);
}

            /*Saritha_b1.............Start...........Reprint Settlement Report */
            // #ifdef TLFB  (Made this feature as the part of CPAC Base Application)

            if (inGGCode() == SETTLE) {
                memset(&srCPACSettleMiddle, 0x00, sizeof(srCPACSettleMiddle));
                strcpy(srCPACSettleMiddle.szCardName, srRcpt.unFrm.srSummary.srMid.szCType);
                strcpy(srCPACSettleMiddle.szCreditCnt, srRcpt.unFrm.srSummary.srMid.szCreditCount);
                strcpy(srCPACSettleMiddle.szCreditTot, srRcpt.unFrm.srSummary.srMid.szCreditTotal);
                strcpy(srCPACSettleMiddle.szDebitCnt, srRcpt.unFrm.srSummary.srMid.szDebitCount);
                strcpy(srCPACSettleMiddle.szDebitTot, srRcpt.unFrm.srSummary.srMid.szDebitTotal);
                strcpy(srCPACSettleMiddle.szShiftNum, srRcpt.unFrm.srSummary.srMid.szShiftNumber);
                strcpy(srCPACSettleMiddle.szSurCharge, srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
                strcpy(srCPACSettleMiddle.szAdjCnt, srRcpt.unFrm.srSummary.srMid.szAdjustCount);
                strcpy(srCPACSettleMiddle.szAdjTot, srRcpt.unFrm.srSummary.srMid.szAdjustTotal);
                strcpy(srCPACSettleMiddle.szReversalCnt, srRcpt.unFrm.srSummary.srMid.szReversalCount);
                strcpy(srCPACSettleMiddle.szReversalTot, srRcpt.unFrm.srSummary.srMid.szReversalTotal);
                strcpy(srCPACSettleMiddle.szNetCnt, srRcpt.unFrm.srSummary.srMid.szNetCount);
                strcpy(srCPACSettleMiddle.szNetTot, srRcpt.unFrm.srSummary.srMid.szNetTotal);
                srCPACSettleMiddle.lnMiddleCond = lnBottomCondition;

                if (inDBFileExists(szSFileName) == VS_SUCCESS)
                    if (inDBWriteRecord(szSFileName, inRecCnt, (unsigned char *) &srCPACSettleMiddle) < 0)
                        ACTIVITY_LOG("Settle Middle Failed");
            }
            // #endif   /* TLFB */  (Made this feature as the part of CPAC Base Application)
            /*Saritha_b1..............End............Reprint Settlement Report */
        }
    }
#if CITI_PHIL
    if (inGGCode() == SETTLE) {
        lnMiddleCondition = lnCPACMiddleCondition;


        if (inPrintLines(&obPrinter, CPAC_SETTLEMENT_STATUS_START, CPAC_SETTLEMENT_STATUS_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
            return(VS_ERR);

        /*Saritha_b1.............Start...........Reprint Settlement Report */
        // #ifdef TLFB  (Made this feature as the part of CPAC Base Application)
        if (inGGCode() == SETTLE) {
            vdGetReprintSettleFileName(szSFileName, CPAC_FOOTER);

            if (inDBFileExists(szSFileName) == VS_SUCCESS)
                inDBRemoveFile(szSFileName);

            if (inDBFileExists(szSFileName) != VS_SUCCESS)
                if (inDBCreateFile(szSFileName, sizeof(srCPACSettleBottom)) != VS_SUCCESS)
                    ACTIVITY_LOG("Bottom fopen failed"); //return(VS_ERROR);

            memset(&srCPACSettleBottom, 0x00, sizeof(srCPACSettleBottom));
            srCPACSettleBottom.lnBottomCond = lnMiddleCondition;

            if (inDBWriteRecord(szSFileName, 1, (unsigned char *) &srCPACSettleBottom) < 0)
                ACTIVITY_LOG("Settle Bottom Failed");

            //inRecCnt++;
        }
        // #endif   /* TLFB */  (Made this feature as the part of CPAC Base Application)
        /*Saritha_b1..............End............Reprint Settlement Report */
    }
#endif /* CITI_PHIL */
    //leo_nosourcesafe
#ifdef CITI_IND
    if (inGGCode() == SETTLE) {
        lnMiddleCondition = lnCPACMiddleCondition;


        if (inPrintLines(&obPrinter, CPAC_SETTLEMENT_STATUS_START, CPAC_SETTLEMENT_STATUS_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
            return(VS_ERR);
    }
#endif /* CITI_IND */

#ifdef CITI_IND

    memcpy(&srRcpt.unFrm.srSubTotal.srTerm, &srTempRcpt.unFrm.srSubTotal.srTerm, sizeof(srRcpt.unFrm.srSubTotal.srTerm));

#endif

    return(VS_SUCCESS);
}


/*-------------------------------------------------------------------------
   Function :    vdSetPrintReceiptConditions()
    Description :
    Parameters :
    Returns :
    Notes :
--------------------------------------------------------------------------*/

void vdSetPrintReceiptConditions(TRANSACTION_OBJECT* pobTran) {
    VS_BOOL fRedLine = VS_FALSE;
    VS_BOOL fBlackLine = VS_FALSE;
    VS_BOOL fTipBlankLine = VS_FALSE;
    VS_BOOL fTaxBlankLine = VS_FALSE;
    VS_BOOL fNoSigLineMsg = VS_FALSE;
    VS_BOOL fDisclaimerSigLine = VS_FALSE;
    VS_BOOL fVisaDebitFields = VS_FALSE;
    VS_BOOL fVisaPurchaseCardFields = VS_FALSE;
    VS_BOOL fTotalLineOnly = VS_FALSE;
    VS_BOOL fOfflineRefund = VS_FALSE;
    VS_BOOL fShowAVS = VS_FALSE;
    VS_BOOL fAuthRRNPrint = VS_TRUE;
	VS_BOOL fEMVFields = VS_FALSE; //jrd for EMV
	VS_BOOL fEMVNoSignLine = VS_FALSE; //jrd for EMV

	int CVMLen=0;
	char btCVM[10];
	char szCVM[20];



    int inTranCode;
    int inAVSMode;
    char szRoom[ROOM_NUM_SIZE + 1];
    /** /pdebug(("--vdSetPrintReceiptConditions--"));*/



    if (inGetPrinterType() == NOPRINTER || !fGetEnablePrinter())
        return;

    if (srRcpt.szAVSCode[0] == NULL_CH)
        inAVSMode = NO_AVS;
    else
        inAVSMode = inGetAVS();

    /* added to correct SPBASE2.5 - include card
       present for setting of print condition for
       AVS - fix from 06/17/99 gw 09/23/99 */

    if (fPhoneTrans(pobTran) || (pobTran->srBRec.inCode == SALE && pobTran->srBRec.fManual == VS_TRUE && fGetCardPresent() == VS_TRUE))
        fShowAVS = VS_TRUE;


    if (pobTran->srBRec.inChipStatus==EMV_CARD)
    {

		fEMVFields = VS_TRUE;

		//jrd line of codes for no signature required
		CVMLen = inGetDataLengthFromBatch(pobTran, FID_EMV_TAG_9F34_CVM_RESULTS_LEN);
		inGetDataFromBatchToEMVPacket(pobTran, FID_EMV_TAG_9F34_CVM_RESULTS, CVMLen, (unsigned char *)&btCVM[0]);

		memset(szCVM, 0x00,sizeof(szCVM));
		//hex_2_asc((BYTE *) &szCVM[0], (BYTE *)btCVM, CVMLen);



		 inGetBatchFieldData(&pobTran->srBRec, CITI_EMV_CVM_RESULTS, (unsigned char *)szCVM, 6);


		if (strcmp(&szCVM[5], "2") == 0)
		{

			fEMVNoSignLine = VS_TRUE;
		}


    }

    inTranCode = inGGCode();
    /*    if (( fRefundTrans(pobTran)|| pobTran->srBKey.fVoided) && (
            inGetPrinterType() != PRINTER_350))
            fRedLine = VS_TRUE;
        else */ // Any way color printing is not there in Thermal printer.
    fBlackLine = VS_TRUE;

    if ((inTranCode == PRE_AUTH || inTranCode == PRE_COMP || inTranCode == SALE || inTranCode == PHONE) && (pobTran->srBRec.inTranCardType != DEBIT_CARD && pobTran->srBRec.inTranCardType != EBT_CARD) && (inGetTipProcessing() > TIP_OFF) && (!fRefundTrans(pobTran)) && (!pobTran->srBKey.fVoided) && (pobTran->srBRec.lnTipAmount == 0L))
       fTipBlankLine = VS_TRUE;


    if ((inTranCode == PRE_AUTH) && (pobTran->srBRec.inTranCardType != DEBIT_CARD && pobTran->srBRec.inTranCardType != EBT_CARD) && (fGetTaxProc() == VS_TRUE) && (pobTran->srBRec.lnTaxAmount == 0L))
        fTaxBlankLine = VS_TRUE;

    if (inTranCode == PRE_AUTH) {
        if (!fGetOpenTabSLine())
            fNoSigLineMsg = VS_TRUE;
    } else if (!fGetSignLine())
        fNoSigLineMsg = VS_TRUE;



    /* bug fix from SPBASE2.5 - 09/23/99 */
    if (inTranCode == PRE_AUTH) {
        if (fGetOpenTabSLine() && (pobTran->srBRec.inPrintOption & PRT_MERCH))
            fDisclaimerSigLine = VS_TRUE;
    } else if (fGetSignLine() && (inTranCode != PRE_AUTH) && (pobTran->srBRec.inPrintOption & PRT_MERCH))
        fDisclaimerSigLine = VS_TRUE;


    strcpy(szRoom, pobTran->srBRec.szRoomNum);


    /* Bug fix ATL#24_44150 from SPBASE2.5 Did not
    print signature line for floor limit transaction */


    /* Make sure No Signature Required msg and Disclaimer line are mutually
    exclusive */

    if (fNoSigLineMsg)
        fDisclaimerSigLine = VS_FALSE;

    if ((pobTran->srBRec.inTranCardType == DEBIT_CARD) && strlen(srRcpt.unFrm.
srReceipt.szRefCustNumber) > 0)
        fVisaDebitFields = VS_TRUE;

    if ((pobTran->srBRec.inTranCardType == PURCHASE_CARD) && strlen(srRcpt.
unFrm.srReceipt.szRefCustNumber) > 0)
        fVisaPurchaseCardFields = VS_TRUE;

    if (pobTran->srBRec.inTranCardType == PURCHASE_CARD)
        fTotalLineOnly = VS_FALSE;
    else if (((inTranCode != PRE_AUTH) && (fGetTaxProc() != VS_TRUE) && (inGetTipProcessing() == TIP_OFF) && (!pobTran->srBRec.lnSChgAmount) && (!pobTran->srBRec.lnCashBackAmount)))
        fTotalLineOnly = VS_TRUE;

    if (inTranCode == AUTH_ONLY || inTranCode == IMAM_CARDVER)
        fTotalLineOnly = VS_TRUE;  /* bb1 DFW 114 */

    if (fRefundTrans(pobTran) && pobTran->srBKey.fOffline)
        fOfflineRefund = VS_TRUE;
    if (inTranCode == AUTH_ONLY || inTranCode == IMAM_CARDVER) //1.4
        fAuthRRNPrint = VS_FALSE;

    lnMiddleCondition = formater_set_flags((fRedLine && fVisaDebitFields),
    (fVisaDebitFields ),
    (fVisaPurchaseCardFields && fGetPrintBatNum()),
    (fRedLine && fVisaPurchaseCardFields &&
    fGetPrintBatNum()),

    (strlen(szRoom) == 0 && pobTran->srBRec.
    inTranCardType == DEBIT_CARD && fGetPrintBatNum()),
    (fRedLine && (strlen(szRoom) == 0) && pobTran->srBRec.
    inTranCardType == DEBIT_CARD && fGetPrintBatNum()),
    (strlen(szRoom) == 0 && pobTran->srBRec.
    inTranCardType != DEBIT_CARD && fGetPrintBatNum()),
    (fRedLine && (strlen(szRoom) == 0) && pobTran->srBRec.
    inTranCardType != DEBIT_CARD && fGetPrintBatNum()),

    (fBlackLine && strlen(srRcpt.unFrm.srReceipt.szServId
    ) > 0),
    (fRedLine && strlen(srRcpt.unFrm.srReceipt.szServId)
    > 0),
    (fRedLine && !fGetPrintBatNum() && (strlen(szRoom)
    == 0)),
    (fBlackLine && !fGetPrintBatNum() && (strlen(szRoom
    ) == 0)),

    (fGetPrintBatNum()),
    (fGetCPACRRNPrint() && fAuthRRNPrint), /* LENIN */
    (fGetCPACUsrInvNum()),/* LENIN */
    ((pobTran->inTransactionCode == REFUND)),

    (fBlackLine && fOfflineRefund),
    (fRedLine && fOfflineRefund),
    (fRedLine && pobTran->srBRec.inTranCardType ==
    DEBIT_CARD),
    (pobTran->srBRec.inTranCardType == DEBIT_CARD),

    (fBlackLine &&  fGetPrePrint() && !(pobTran->srBRec
    .inPrintOption & PRT_DUPLICATE) && ( inTranCode != ROOMCHARGE ) && (!
    fOfflineRefund)),
    (fRedLine   &&  fGetPrePrint() && !(pobTran->srBRec
    .inPrintOption & PRT_DUPLICATE) && ( inTranCode != ROOMCHARGE ) && (!
    fOfflineRefund)),
#ifndef HKGM //Kelvin_F2 --- start: set the manual/holder name condition
    (fBlackLine && (!fGetPrePrint() || pobTran->srBRec.
inPrintOption & PRT_DUPLICATE) && (inTranCode != ROOMCHARGE) && (!fOfflineRefund) && fGetPrintDisclaimer()),
#endif //Kelvin_F2 --- end: set the manula/holder name conditon
#ifdef HKGM //Kelvin_F2 --- start: set the manual/holder name condition
    (strlen(srRcpt.unFrm.srReceipt.szCHolder) != 0),
#endif //Kelvin_F2 --- end: set the manula/holder name conditon
    (fRedLine && (!fGetPrePrint() || pobTran->srBRec.
inPrintOption & PRT_DUPLICATE) && (inTranCode != ROOMCHARGE) && (!fOfflineRefund) && fGetPrintDisclaimer()),

    (fPhoneTrans(pobTran) && fRedLine && (inAVSMode != NO_AVS)),
//jrd enter code here for EMV printout  spqalog
    (fEMVFields && ((pobTran->inTransactionCode != REFUND)/*||(pobTran->inTransactionCode != AUTH_ONLY)*/)),//KiaSoon 070206: Modified
    (fEMVNoSignLine),
    /*(fBlackLine && (inTranCode == ROOMCHARGE)),*/
    (fRedLine && (inTranCode == ROOMCHARGE)),

    (inTranCode == PRE_AUTH),
    (!fPhoneTrans(pobTran) && fRedLine && (inTranCode != PRE_AUTH) || (fPhoneTrans(pobTran) && fRedLine && inAVSMode == NO_AVS)),
    (fPhoneTrans(pobTran) && fBlackLine && (inAVSMode != NO_AVS)),
    (!fPhoneTrans(pobTran) && fBlackLine && (inTranCode != PRE_AUTH) || (fPhoneTrans(pobTran) && fBlackLine && inAVSMode == NO_AVS)), -1 );

    lnBottomCondition = formater_set_flags((fRedLine && inTranCode == REFUND_DEBIT), (fBlackLine && inTranCode == REFUND_DEBIT), (fBlackLine && (pobTran->srBRec.inPrintOption & PRT_BANK)), (fBlackLine && (pobTran->srBRec.inPrintOption & PRT_CUST)), (fGetPrintDisclaimer() && !fNoSigLineMsg), ((inGetPrinterType() != PRINTER_350) && fBlackLine), ((inGetPrinterType() != PRINTER_350) && fRedLine), ((inGetPrinterType() != PRINTER_350) && fBlackLine), (fRedLine && fGetSugTipOn() && inGetTipProcessing() > TIP_OFF && fTipBlankLine),
                        (fBlackLine && (inTranCode != PRE_AUTH) && !fTotalLineOnly),
                        (fRedLine && (inTranCode != PRE_AUTH) && !fTotalLineOnly),
                        (!pobTran->srBKey.fVoided && !fRefundTrans(pobTran) && !fTotalLineOnly),

                        (fRedLine && (pobTran->srBRec.lnSChgAmount > 0L)),
                        (fBlackLine && (pobTran->srBRec.lnSChgAmount > 0L)),
                        (fRedLine && inTranCode != PRE_AUTH),
                        (fBlackLine && !fTipBlankLine && !fTaxBlankLine && inTranCode != PRE_AUTH),

                        (fRedLine && pobTran->srBRec.lnCashBackAmount > 0),
                        (fBlackLine && pobTran->srBRec.lnCashBackAmount > 0),
                        (fRedLine),
                        (fBlackLine && fGetSugTipOn() && inGetTipProcessing() > TIP_OFF && fTipBlankLine),

                        (fBlackLine && fNoSigLineMsg),
                        (fRedLine && fNoSigLineMsg),
                        ((fBlackLine && !fNoSigLineMsg) && fDisclaimerSigLine),
                        ((fRedLine && !fNoSigLineMsg) && fDisclaimerSigLine),

                        (fRedLine && pobTran->srBRec.fTaxEntered && !fTaxBlankLine),
                        (fBlackLine && pobTran->srBRec.fTaxEntered && !fTaxBlankLine),
                        (fBlackLine && fTaxBlankLine),
                        (!fNoSigLineMsg && fDisclaimerSigLine && inGetPrinterType() == PRINTER_350),

                        (fRedLine && pobTran->srBRec.fTipEntered && !fTipBlankLine),
                        (fBlackLine && pobTran->srBRec.fTipEntered && !fTipBlankLine),
                        (fBlackLine && fTipBlankLine),
                        0, -1);



}





/*-------------------------------------------------------------------------
   Function :    vdSetReceiptFooterConditions()
    Description :
    Parameters :
    Returns :
    Notes :
--------------------------------------------------------------------------*/

void vdSetReceiptFooterConditions(TRANSACTION_OBJECT* pobTran) {
    VS_BOOL fRedLine = VS_FALSE;
    VS_BOOL fBlackLine = VS_FALSE;
    VS_BOOL fNoSigLineMsg = VS_FALSE;

    int inTranCode;

    inTranCode = inGGCode();

    if ((fRefundTrans(pobTran) || pobTran->srBKey.fVoided) && (inGetPrinterType() != PRINTER_350))
        fRedLine = VS_TRUE;
    else
        fBlackLine = VS_TRUE;

    /*    if (((pobTran->srBRec.inTranCardType == DEBIT_CARD) && !fGetDebitSign
    ()) ||*/
    if (!fGetSignLine() || (inTranCode == PRE_AUTH && !fGetOpenTabSLine()))
        fNoSigLineMsg = VS_TRUE;

    lnBottomCondition = formater_set_flags((fRedLine && (strlen(srRcpt.szSpecialMessage)) > 0),
                        (fBlackLine && strlen(srRcpt.szSpecialMessage) > 0),
                        (fRedLine && (strlen(srRcpt.szStatusMessage)) > 0),
                        (fBlackLine && strlen(srRcpt.szStatusMessage) > 0),

                        (fRedLine && (strlen(srRcpt.szStatus2Message)) > 0),
                        (fBlackLine && strlen(srRcpt.szStatus2Message) > 0),
                        (fRedLine && (strlen(srRcpt.szErrorMessage)) > 0),
                        (fBlackLine && strlen(srRcpt.szErrorMessage) > 0),

                        0,
                        0,
                        0,
                        0,

                        0,
                        0,
                        0,
                        0,

                        0,
                        0,
                        0,
                        ((inGetPrinterType() != PRINTER_350)),

                        (fNoSigLineMsg),
                        0,
                        0,
                        0,

                        0,
                        0,
                        0,
                        0,

                        0,
                        0,
                        0,
                        0, -1);
}



/*-------------------------------------------------------------------------
   Function :    inPrintReceiptFooterLines
    Description :
    Parameters :
    Returns :
    Globals :
    Notes :
    Modification History :
      #     Date      Who                     Description
    ----- -------- ---------- ---------------------------------------------
      0   02/10/98 KC_C1      Copy from NPC 37490 system
--------------------------------------------------------------------------*/

int inPrintReceiptFooterLines(PRINTER_OBJECT* obPrinter) {
    if (inPrintLines(obPrinter, CPAC_RECEIPT_FOOTER_START, CPAC_RECEIPT_FOOTER_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
        return(VS_ERR);

    return(VS_SUCCESS);
}



/*********************************************************************************************
* @func int | inCPACPrintDetailGrandTotal |
*
*       Browse the Acummulators and print items with totals.
*
* @parm PRINTER_OBJECT * | pobPrinter |
* @parm TRANSACTION_OBJECT * | pobTran |
*
* @rdesc return values.
* @flag int    |  VS_SUCCESS
* @flag int    |  VS_ERR
* @end

**********************************************************************************************/


int inCPACPrintDetailGrandTotal(PRINTER_OBJECT* pobPrinter,TRANSACTION_OBJECT* pobTran,int* pinReportTop,int inNumberOfMerchants) {
    //    int inHostIdx; CPAC_LINT_REMOVED
    int inNewHost;
    //  CARD_TOTS_REC srGrandTots; CPAC_LINT_REMOVED
    int inIssuer;
    int inIssuerCnt;
    int inGrandIssuerCnt = 0;
    int inRetVal = 0;
    long lnRecNum = 0;
    int inNegPos;
    char szCurSym[CUR_SYMBOL_SIZE + 1];
    long lnCount = 0,
    lnAmount = 0,
    lnTip = 0,
    lnTotal = 0,
    lnTax = 0,
    lnSurCharge = 0,
    lnCashBack = 0;
    long lnDebitCount = 0,
    lnCreditCount = 0,
    lnAdjustCount = 0,
    lnNetCount = 0;
    long lnDebitAmount = 0,
    lnCreditAmount = 0,
    lnAdjustAmount = 0,
    lnNetAmount = 0;
    long lnSaleCount = 0,
    lnRefundCount = 0,
    lnVoidSaleCount = 0,
    lnVoidRefundCount = 0,
    lnTotalCount = 0;
    unsigned char ucIITTempRec[SIZE_IIT_REC + 1];

    double dbSaleAmount = 0.0,
    dbRefundAmount = 0.0,
    dbVoidSaleAmount = 0.0,
    dbVoidRefundAmount = 0.0,
    dbTotalAmount = 0.0;
    double dbTipAmount = 0.0,
    dbGrandTipAmount = 0.0;
    double dbGrandSaleAmount = 0,
    dbGrandRefundAmount = 0,
    dbGrandVoidSaleAmount = 0,
    dbGrandVoidRefundAmount = 0,
    dbGrandTotalAmount = 0;
    long lnGrandSaleCount = 0,
    lnGrandRefundCount = 0,
    lnGrandVoidSaleCount = 0,
    lnGrandVoidRefundCount = 0,
    lnGrandTotalCount = 0;



    char szFileName[FILENAME_SIZE + 1];
    DB_FILE srDBFPtr;
    ACCUM_REC srAccumRec;
    ACCUM_KEY srAccumKey;
    ACCUM_SKEY srAccumSKey;
    int inKeyIdx = 0;
    int inResult = 0;
    FHANDLE hFHandle;
    ACCUM_SHIFT srASI;
    /* LENIN CPAC #if TBD_CPAC */
    //  IIT_REC srCPACIITRec; cpac_2.2a
    /* LENIN CPAC #endif  TBD_CPAC */


    vdSetHostHandle(inGlobalHostHandle);
    // vdGetAccumFName (szFileName);
    sprintf(szFileName, "ACC%02d%02d", inGlobalHostHandle, inGetMerchantNum());
    if (inOpenAccum(&srDBFPtr, szFileName) != VS_SUCCESS) {

        vdSGErrorMessage(BATCH_ERR_MSG);
        return(VS_ERR);
    }


    /*  Read ASI File to use for determining if issuer accumulator has been updated */


    // vdGetASIFName(szFileName);
    sprintf(szFileName, "ASI%02d%02d.DAT", inGlobalHostHandle, inGetMerchantNum());
    if ((hFHandle = open(szFileName, O_RDWR)) < 0) {
        if ((hFHandle = open(szFileName, O_CREAT | O_RDWR)) < 0)
            return(VS_ERR);

        memset((char *) &srASI, 0x00, SIZE_ACCUM_SHIFT);
    } else
        inResult = read(hFHandle, (char *) &srASI, SIZE_ACCUM_SHIFT);

    close(hFHandle);

    srAccumSKey.compare_func = inAccumCompFn;
    inNewHost = VS_TRUE;
    inIssuerCnt = 0;
    if (inPrintLines(pobPrinter, CPAC_CREDIT_LABEL_START, CPAC_CREDIT_LABEL_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
        return(VS_ERR);

    for (inIssuer = 0; inIssuer < TOTAL_ISSUERS; inIssuer++)  // __TBD__CPAC
    {
#if 0
    if (srASI.srIssuer.fActiveAccum[inIssuer] == '\0')
        continue;

inGetIssuerRecord(inIssuer);
strlcpy(srRcpt.unFrm.srSummary.srMid.szCType, srCPACIITRec.szIssuerLabel, CLABEL_SIZE);
    srAccumKey.inIssuerNumber = inIssuer;
    srAccumSKey.accumKey.inIssuerNumber = inIssuer;
#endif /* 0 */
        if ((inLoadIITRecFromStruct(inIssuer, ucIITTempRec)) == VS_ERR) {
            inCloseAccum(&srDBFPtr);
            vdSGErrorMessage(IIT_ERR_MSG21);
            return(VS_ERR);
        }

        if (srASI.srIssuer.fActiveAccum[inGetIssuerNumberFromStruct(ucIITTempRec)] == '\0')
            continue;

        strlcpy(srRcpt.unFrm.srSummary.srMid.szCType, szGetIssuerLabelFromStruct(ucIITTempRec), CLABEL_SIZE);



        srAccumKey.inIssuerNumber = inGetIssuerNumberFromStruct(ucIITTempRec);
        srAccumSKey.accumKey.inIssuerNumber = inGetIssuerNumberFromStruct(ucIITTempRec);


        inRetVal = inKeyReadAccum(&srDBFPtr, &srAccumRec, &srAccumKey, &srAccumSKey, &lnRecNum);
        if (inRetVal == VS_SUCCESS) {
            strcpy(srRcpt.szBatchNum, pobTran->szBatchNum);/* Lenin */
            if (inNewHost) {
                if (*pinReportTop == VS_TRUE) {
                    if (inGetMITTotRecs() == 1 || inNumberOfMerchants == 1)
                        sprintf(srRcpt.szBatchNum, "%03ld", lnGetBatchNum());
                    else
                        sprintf(srRcpt.szBatchNum, "%03ld", lnGetBatchNum());
                }

                inNewHost = VS_FALSE;

                *pinReportTop = VS_FALSE;

                strlcpy(srRcpt.szMerchantName, szGetMerchantText(), sizeof(srRcpt.szMerchantName));
                strlcpy(srRcpt.szHostName, szGetHostName(), sizeof(srRcpt.szHostName));
            }
            /*  Use totals from record */


            lnSaleCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].lnCount[SALE_TRAN] ;

            lnRefundCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[REFUND_TRAN] + srAccumRec.srTotals[DEBIT_CARD].lnCount[REFUND_TRAN];

            lnVoidSaleCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[VOID_SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].lnCount[VOID_SALE_TRAN];

            lnVoidRefundCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[VOID_REFUND_TRAN] + srAccumRec.srTotals[DEBIT_CARD].lnCount[VOID_REFUND_TRAN];


            lnTotalCount = lnSaleCount + lnRefundCount + lnVoidSaleCount + lnVoidRefundCount;

            /* lnCreditCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[SALE_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnCount[SALE_TRAN] ;
            lnDebitCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[REFUND_TRAN]                          + srAccumRec.srTotals[DEBIT_CARD].lnCount[REFUND_TRAN];
              lnCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[SALE_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnCount[SALE_TRAN] +
                        srAccumRec.srTotals[CREDIT_CARD].lnCount[REFUND_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnCount[REFUND_TRAN];
            */


            dbSaleAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbAmount[SALE_TRAN];
            dbRefundAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[REFUND_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbAmount[REFUND_TRAN];

            dbVoidSaleAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[VOID_SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbAmount[VOID_SALE_TRAN];

            dbVoidRefundAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[VOID_REFUND_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbAmount[VOID_REFUND_TRAN];
            dbTipAmount = srAccumRec.srTotals[CREDIT_CARD].dbTip[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbTip[SALE_TRAN];
            /*  lnAmount= srAccumRec.srTotals[CREDIT_CARD].lnAmount[SALE_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnAmount[SALE_TRAN] -
                        srAccumRec.srTotals[CREDIT_CARD].lnAmount[REFUND_TRAN] -
                        srAccumRec.srTotals[DEBIT_CARD].lnAmount[REFUND_TRAN];
              lnTip   = srAccumRec.srTotals[CREDIT_CARD].lnTip[SALE_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnTip[SALE_TRAN] -
                        srAccumRec.srTotals[CREDIT_CARD].lnTip[REFUND_TRAN] -
                        srAccumRec.srTotals[DEBIT_CARD].lnTip[REFUND_TRAN];
              lnTax   = srAccumRec.srTotals[CREDIT_CARD].lnTax[SALE_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnTax[SALE_TRAN] -
                        srAccumRec.srTotals[CREDIT_CARD].lnTax[REFUND_TRAN] -
                        srAccumRec.srTotals[DEBIT_CARD].lnTax[REFUND_TRAN];
              lnSurCharge   = srAccumRec.srTotals[CREDIT_CARD].lnSurCharge[SALE_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnSurCharge[SALE_TRAN] -
                        srAccumRec.srTotals[CREDIT_CARD].lnSurCharge[REFUND_TRAN] -
                        srAccumRec.srTotals[DEBIT_CARD].lnSurCharge[REFUND_TRAN];
              lnCashBack   = srAccumRec.srTotals[CREDIT_CARD].lnCashBack[SALE_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnCashBack[SALE_TRAN] -
                        srAccumRec.srTotals[CREDIT_CARD].lnCashBack[REFUND_TRAN] -
                        srAccumRec.srTotals[DEBIT_CARD].lnCashBack[REFUND_TRAN];
            */
            dbTotalAmount = dbSaleAmount - dbRefundAmount;


            /* Set print line */
            sprintf(srRcpt.unFrm.srSummary.srMid.szCreditCount, SUBSTITUTE_LD, lnSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szDebitCount, SUBSTITUTE_LD, lnRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustCount, SUBSTITUTE_LD, lnVoidSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szReversalCount, SUBSTITUTE_LD, lnVoidRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szNetCount, SUBSTITUTE_LD, lnTotalCount);

            /* Total Amount */
            vdDb2Str(dbSaleAmount, srRcpt.unFrm.srSummary.srMid.szCreditTotal);
            vdDb2Str(dbRefundAmount, srRcpt.unFrm.srSummary.srMid.szDebitTotal);
            vdDb2Str(dbVoidSaleAmount, srRcpt.unFrm.srSummary.srMid.szAdjustTotal);
            vdDb2Str(dbVoidRefundAmount, srRcpt.unFrm.srSummary.srMid.szReversalTotal);
            vdDb2Str(dbTotalAmount, srRcpt.unFrm.srSummary.srMid.szNetTotal);
            vdDb2Str(dbTipAmount, srRcpt.unFrm.srSummary.srMid.szCashBackTotal);

            //            sprintf(srRcpt.unFrm.srSummary.srMid.szCreditTotal, SUBSTITUTE_LD, lnSaleAmount);

            //  sprintf(srRcpt.unFrm.srSummary.srMid.szDebitTotal, SUBSTITUTE_LD, lnRefundAmount);
            //           sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, SUBSTITUTE_LD, lnVoidSaleAmount);
            //   sprintf(srRcpt.unFrm.srSummary.srMid.szReversalTotal, SUBSTITUTE_LD, lnVoidRefundAmount);
            //     sprintf(srRcpt.unFrm.srSummary.srMid.szNetTotal, SUBSTITUTE_LD, lnTotalAmount);



            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCreditTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szDebitTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szReversalTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szNetTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCashBackTotal, VS_TRUE);
            /*
                            if ((lnSaleAmount - lnRefundAmount)< -999999999L) {

                            vdGetCSTCurSymbol(szCurSym);
                            inNegPos=strlen(szCurSym);
                            srRcpt.unFrm.srSummary.srMid.szNetTotal[inNegPos]='-';

                         }
            */ // KK commented it out to avoid two '-' symbols from the total.


            if (inPrintLines(pobPrinter, CPAC_DETAIL_TOTAL_START, CPAC_DETAIL_TOTAL_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
                return(VS_ERR);

            if (act_kbd_pending_test(KEY_CANCEL))
                return(VS_ESCAPE);

            /* Accumulate totals */




            lnGrandTotalCount += (int) (lnSaleCount + lnRefundCount + lnVoidSaleCount + lnVoidRefundCount);
            dbGrandSaleAmount += dbSaleAmount;
            dbGrandRefundAmount += dbRefundAmount;
            dbGrandVoidSaleAmount += dbVoidSaleAmount;
            dbGrandVoidRefundAmount += dbVoidRefundAmount;
            dbGrandTipAmount += dbTipAmount;



            //( lnSaleCount+lnRefundCount+lnVoidSaleCount+lnVoidRefundCount);


            inIssuerCnt++;
            if (inIssuerCnt > inGrandIssuerCnt)
                inGrandIssuerCnt = inIssuerCnt;
        }
    }
    inCloseAccum(&srDBFPtr);

#ifdef ICICI
	//venu_corrected to print the tiptotals in detail report if only one card range cards are swipped
	if(inIssuerCnt == 1)
	{
 inLoadTCTRec(0);
 if(inGetTipProcessing() ==1)
 	{
  		if(inPrintLines(&obPrinter, 55, 56, NO_BL_LINE, 0L) != VS_SUCCESS)
  		return(VS_ERR);
	}
}//}
    	/* Print Grand Totals if more than one issuer */
    	if (inIssuerCnt > 1)
	{
       	if (inGrandIssuerCnt > 1)
		{
#else
	/* Print Grand Totals if more than one issuer */
    	if (inIssuerCnt > 1)
	{
       	if (inGrandIssuerCnt > 1)
		{

#endif   /* ICICI  */
#if 0 /* LENIN */
    /* Set print line */
    sprintf(srRcpt.unFrm.srSummary.srMid.szCreditCount, SUBSTITUTE_D,
        srGrandTots/*[TOTAL_ISSUERS]*/.inTotalCnt);
    /* Total Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szCreditTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnTotalAmt);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCreditTotal);
    /* Sale Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szDebitTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnSaleAmt);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szDebitTotal);
    /*Tip Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnTipAmt);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szAdjustTotal);
    /*Tax Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szTaxTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnTaxAmt);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szTaxTotal);
    /*Surcharge Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnSurCharge);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
    /*CashBack Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szCashBackTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnCashBack);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCashBackTotal);
    /* Send VS_TRUE so FORM_FEED will print */
    #endif /* 0 */

            dbGrandTotalAmount = dbGrandSaleAmount - dbGrandRefundAmount;

            sprintf(srRcpt.unFrm.srSummary.srMid.szCreditCount, SUBSTITUTE_LD, lnGrandSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szDebitCount, SUBSTITUTE_LD, lnGrandRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustCount, SUBSTITUTE_LD, lnGrandVoidSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szReversalCount, SUBSTITUTE_LD, lnGrandVoidRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szNetCount, SUBSTITUTE_LD, lnGrandTotalCount);

            vdDb2Str(dbGrandSaleAmount, srRcpt.unFrm.srSummary.srMid.szCreditTotal);
            vdDb2Str(dbGrandRefundAmount, srRcpt.unFrm.srSummary.srMid.szDebitTotal);
            vdDb2Str(dbGrandVoidSaleAmount, srRcpt.unFrm.srSummary.srMid.szAdjustTotal);

            vdDb2Str(dbGrandVoidRefundAmount, srRcpt.unFrm.srSummary.srMid.szReversalTotal);
            vdDb2Str(dbGrandTotalAmount, srRcpt.unFrm.srSummary.srMid.szNetTotal);
            vdDb2Str(dbGrandTipAmount, srRcpt.unFrm.srSummary.srMid.szCashBackTotal);
            //vdDb2Str(dbGrandOfflineAmount,srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);

            /*  sprintf(srRcpt.unFrm.srSummary.srMid.szCreditTotal, SUBSTITUTE_LD, lnGrandSaleAmount);
                       sprintf(srRcpt.unFrm.srSummary.srMid.szDebitTotal, SUBSTITUTE_LD, lnGrandRefundAmount);
                       sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, SUBSTITUTE_LD, lnGrandVoidSaleAmount);
                       sprintf(srRcpt.unFrm.srSummary.srMid.szReversalTotal, SUBSTITUTE_LD, lnGrandVoidRefundAmount);
                       sprintf(srRcpt.unFrm.srSummary.srMid.szNetTotal, SUBSTITUTE_LD, lnGrandTotalAmount);
            */
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCreditTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szDebitTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szReversalTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szNetTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCashBackTotal, VS_TRUE);

            if ((dbGrandSaleAmount - dbGrandRefundAmount) < -999999999999.00) {
                strcpy(szCurSym, szGetCurSymbol());
                inNegPos = strlen(szCurSym);
                srRcpt.unFrm.srSummary.srMid.szNetTotal[inNegPos] = '-';
            }

            // vdCPACSetSummaryBottomCondition (pobTran, VS_TRUE, &srGrandTots/*[TOTAL_ISSUERS]*/);
                if(inGetTipProcessing() == 0)
                	{
            if (inPrintLines(pobPrinter, CPAC_TOTAL_LABEL_START, CPAC_TOTAL_LABEL_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
                return(VS_ERR);
                	}
		else
			if (inPrintLines(pobPrinter, CPAC_TOTAL_LABEL_START, 56, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
                return(VS_ERR);
            // if(inPrintLines(pobPrinter, DETAIL_FORM_FEED, DETAIL_BOTTOM_END, NO_BL_LINE, 0x80000000) != VS_SUCCESS)
            //   return(VS_ERR);
        }
    }
    if (inPrintLines(pobPrinter, CPAC_EMPTY_LINE_START, CPAC_EMPTY_LINE_END, 0, 0L) != VS_SUCCESS)
        return (VS_ERR);

    if (inPrintLines(pobPrinter, CPAC_END_OF_REPORT_START, CPAC_END_OF_REPORT_END, NO_BL_LINE, 0x80000000) != VS_SUCCESS)
        return(VS_ERR);
    return(VS_SUCCESS);
}


int inImamPrintDetailGrandTotal(PRINTER_OBJECT* pobPrinter,TRANSACTION_OBJECT* pobTran,int* pinReportTop,int inNumberOfMerchants) 
{
    //    int inHostIdx; CPAC_LINT_REMOVED
    int inNewHost;
    //  CARD_TOTS_REC srGrandTots; CPAC_LINT_REMOVED
    int inIssuer;
    int inIssuerCnt;
    int inGrandIssuerCnt = 0;
    int inRetVal = 0;
    long lnRecNum = 0;
    int inNegPos;
    char szCurSym[CUR_SYMBOL_SIZE + 1];
    long lnCount = 0,
    lnAmount = 0,
    lnTip = 0,
    lnTotal = 0,
    lnTax = 0,
    lnSurCharge = 0,
    lnCashBack = 0;
    long lnDebitCount = 0,
    lnCreditCount = 0,
    lnAdjustCount = 0,
    lnNetCount = 0;
    long lnDebitAmount = 0,
    lnCreditAmount = 0,
    lnAdjustAmount = 0,
    lnNetAmount = 0;
    long lnSaleCount = 0,
    lnRefundCount = 0,
    lnVoidSaleCount = 0,
    lnVoidRefundCount = 0,
    lnTotalCount = 0;
    unsigned char ucIITTempRec[SIZE_CDT_REC + 1];

    double dbSaleAmount = 0.0,
    dbRefundAmount = 0.0,
    dbVoidSaleAmount = 0.0,
    dbVoidRefundAmount = 0.0,
    dbTotalAmount = 0.0;
    double dbTipAmount = 0.0,
    dbGrandTipAmount = 0.0;
    double dbGrandSaleAmount = 0,
    dbGrandRefundAmount = 0,
    dbGrandVoidSaleAmount = 0,
    dbGrandVoidRefundAmount = 0,
    dbGrandTotalAmount = 0;
    long lnGrandSaleCount = 0,
    lnGrandRefundCount = 0,
    lnGrandVoidSaleCount = 0,
    lnGrandVoidRefundCount = 0,
    lnGrandTotalCount = 0;



    char szFileName[FILENAME_SIZE + 1];
    DB_FILE srDBFPtr;
    ACCUM_REC srAccumRec;
    ACCUM_KEY srAccumKey;
    ACCUM_SKEY srAccumSKey;
    int inKeyIdx = 0;
    int inResult = 0;
    FHANDLE hFHandle;
    ACCUM_SHIFT srASI;
    /* LENIN CPAC #if TBD_CPAC */
    //  IIT_REC srCPACIITRec; cpac_2.2a
    /* LENIN CPAC #endif  TBD_CPAC */

	LOG_PRINTFF((0x08L, "==inImamCPACPrintDetailGrandTotal=="));
    vdSetHostHandle(inGlobalHostHandle);
    // vdGetAccumFName (szFileName);
    sprintf(szFileName, "ACC%02d%02d", inGlobalHostHandle, inGetMerchantNum());
    if (inOpenAccum(&srDBFPtr, szFileName) != VS_SUCCESS) {

        vdSGErrorMessage(BATCH_ERR_MSG);
        return(VS_ERR);
    }


    /*  Read ASI File to use for determining if issuer accumulator has been updated */


    // vdGetASIFName(szFileName);
    sprintf(szFileName, "ASI%02d%02d.DAT", inGlobalHostHandle, inGetMerchantNum());
    if ((hFHandle = open(szFileName, O_RDWR)) < 0) {
        if ((hFHandle = open(szFileName, O_CREAT | O_RDWR)) < 0)
            return(VS_ERR);

        memset((char *) &srASI, 0x00, SIZE_ACCUM_SHIFT);
    } else
        inResult = read(hFHandle, (char *) &srASI, SIZE_ACCUM_SHIFT);

    close(hFHandle);

    srAccumSKey.compare_func = inAccumCompFn;
    inNewHost = VS_TRUE;
    inIssuerCnt = 0;
    if (inPrintLines(pobPrinter, CPAC_CREDIT_LABEL_START, CPAC_CREDIT_LABEL_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
        return(VS_ERR);

    for (inIssuer = 0; inIssuer < inGetCDTTotRecs(); inIssuer++)  // __TBD__CPAC
    {
#if 0
    if (srASI.srIssuer.fActiveAccum[inIssuer] == '\0')
        continue;

inGetIssuerRecord(inIssuer);
strlcpy(srRcpt.unFrm.srSummary.srMid.szCType, srCPACIITRec.szIssuerLabel, CLABEL_SIZE);
    srAccumKey.inIssuerNumber = inIssuer;
    srAccumSKey.accumKey.inIssuerNumber = inIssuer;
#endif /* 0 */
        if ((inLoadCDTRecFromStruct(inIssuer, ucIITTempRec)) == VS_ERR) {
            inCloseAccum(&srDBFPtr);
            vdSGErrorMessage(IIT_ERR_MSG21);
            return(VS_ERR);
        }

        if (srASI.srIssuer.fActiveAccum[inGetImamCDTIndexFromStruct(ucIITTempRec)] == '\0')
            continue;

        strlcpy(srRcpt.unFrm.srSummary.srMid.szCType, szGetCardLabelFromStruct(ucIITTempRec), CLABEL_SIZE);



        srAccumKey.inIssuerNumber = inGetImamCDTIndexFromStruct(ucIITTempRec);
        srAccumSKey.accumKey.inIssuerNumber = inGetImamCDTIndexFromStruct(ucIITTempRec);


        inRetVal = inKeyReadAccum(&srDBFPtr, &srAccumRec, &srAccumKey, &srAccumSKey, &lnRecNum);
        if (inRetVal == VS_SUCCESS) {
            strcpy(srRcpt.szBatchNum, pobTran->szBatchNum);/* Lenin */
            if (inNewHost) {
                if (*pinReportTop == VS_TRUE) {
                    if (inGetMITTotRecs() == 1 || inNumberOfMerchants == 1)
                        sprintf(srRcpt.szBatchNum, "%03ld", lnGetBatchNum());
                    else
                        sprintf(srRcpt.szBatchNum, "%03ld", lnGetBatchNum());
                }

                inNewHost = VS_FALSE;

                *pinReportTop = VS_FALSE;

                strlcpy(srRcpt.szMerchantName, szGetMerchantText(), sizeof(srRcpt.szMerchantName));
                strlcpy(srRcpt.szHostName, szGetHostName(), sizeof(srRcpt.szHostName));
            }
            /*  Use totals from record */


            lnSaleCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].lnCount[SALE_TRAN] ;

            lnRefundCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[REFUND_TRAN] + srAccumRec.srTotals[DEBIT_CARD].lnCount[REFUND_TRAN];

            lnVoidSaleCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[VOID_SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].lnCount[VOID_SALE_TRAN];

            lnVoidRefundCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[VOID_REFUND_TRAN] + srAccumRec.srTotals[DEBIT_CARD].lnCount[VOID_REFUND_TRAN];


            lnTotalCount = lnSaleCount + lnRefundCount + lnVoidSaleCount + lnVoidRefundCount;

            /* lnCreditCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[SALE_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnCount[SALE_TRAN] ;
            lnDebitCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[REFUND_TRAN]                          + srAccumRec.srTotals[DEBIT_CARD].lnCount[REFUND_TRAN];
              lnCount = srAccumRec.srTotals[CREDIT_CARD].lnCount[SALE_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnCount[SALE_TRAN] +
                        srAccumRec.srTotals[CREDIT_CARD].lnCount[REFUND_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnCount[REFUND_TRAN];
            */


            dbSaleAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbAmount[SALE_TRAN];
            dbRefundAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[REFUND_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbAmount[REFUND_TRAN];

            dbVoidSaleAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[VOID_SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbAmount[VOID_SALE_TRAN];

            dbVoidRefundAmount = srAccumRec.srTotals[CREDIT_CARD].dbAmount[VOID_REFUND_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbAmount[VOID_REFUND_TRAN];
            dbTipAmount = srAccumRec.srTotals[CREDIT_CARD].dbTip[SALE_TRAN] + srAccumRec.srTotals[DEBIT_CARD].dbTip[SALE_TRAN];
            /*  lnAmount= srAccumRec.srTotals[CREDIT_CARD].lnAmount[SALE_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnAmount[SALE_TRAN] -
                        srAccumRec.srTotals[CREDIT_CARD].lnAmount[REFUND_TRAN] -
                        srAccumRec.srTotals[DEBIT_CARD].lnAmount[REFUND_TRAN];
              lnTip   = srAccumRec.srTotals[CREDIT_CARD].lnTip[SALE_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnTip[SALE_TRAN] -
                        srAccumRec.srTotals[CREDIT_CARD].lnTip[REFUND_TRAN] -
                        srAccumRec.srTotals[DEBIT_CARD].lnTip[REFUND_TRAN];
              lnTax   = srAccumRec.srTotals[CREDIT_CARD].lnTax[SALE_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnTax[SALE_TRAN] -
                        srAccumRec.srTotals[CREDIT_CARD].lnTax[REFUND_TRAN] -
                        srAccumRec.srTotals[DEBIT_CARD].lnTax[REFUND_TRAN];
              lnSurCharge   = srAccumRec.srTotals[CREDIT_CARD].lnSurCharge[SALE_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnSurCharge[SALE_TRAN] -
                        srAccumRec.srTotals[CREDIT_CARD].lnSurCharge[REFUND_TRAN] -
                        srAccumRec.srTotals[DEBIT_CARD].lnSurCharge[REFUND_TRAN];
              lnCashBack   = srAccumRec.srTotals[CREDIT_CARD].lnCashBack[SALE_TRAN] +
                        srAccumRec.srTotals[DEBIT_CARD].lnCashBack[SALE_TRAN] -
                        srAccumRec.srTotals[CREDIT_CARD].lnCashBack[REFUND_TRAN] -
                        srAccumRec.srTotals[DEBIT_CARD].lnCashBack[REFUND_TRAN];
            */
            dbTotalAmount = dbSaleAmount - dbRefundAmount;


            /* Set print line */
            sprintf(srRcpt.unFrm.srSummary.srMid.szCreditCount, SUBSTITUTE_LD, lnSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szDebitCount, SUBSTITUTE_LD, lnRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustCount, SUBSTITUTE_LD, lnVoidSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szReversalCount, SUBSTITUTE_LD, lnVoidRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szNetCount, SUBSTITUTE_LD, lnTotalCount);

            /* Total Amount */
            vdDb2Str(dbSaleAmount, srRcpt.unFrm.srSummary.srMid.szCreditTotal);
            vdDb2Str(dbRefundAmount, srRcpt.unFrm.srSummary.srMid.szDebitTotal);
            vdDb2Str(dbVoidSaleAmount, srRcpt.unFrm.srSummary.srMid.szAdjustTotal);
            vdDb2Str(dbVoidRefundAmount, srRcpt.unFrm.srSummary.srMid.szReversalTotal);
            vdDb2Str(dbTotalAmount, srRcpt.unFrm.srSummary.srMid.szNetTotal);
            vdDb2Str(dbTipAmount, srRcpt.unFrm.srSummary.srMid.szCashBackTotal);

            //            sprintf(srRcpt.unFrm.srSummary.srMid.szCreditTotal, SUBSTITUTE_LD, lnSaleAmount);

            //  sprintf(srRcpt.unFrm.srSummary.srMid.szDebitTotal, SUBSTITUTE_LD, lnRefundAmount);
            //           sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, SUBSTITUTE_LD, lnVoidSaleAmount);
            //   sprintf(srRcpt.unFrm.srSummary.srMid.szReversalTotal, SUBSTITUTE_LD, lnVoidRefundAmount);
            //     sprintf(srRcpt.unFrm.srSummary.srMid.szNetTotal, SUBSTITUTE_LD, lnTotalAmount);



            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCreditTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szDebitTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szReversalTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szNetTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCashBackTotal, VS_TRUE);
            /*
                            if ((lnSaleAmount - lnRefundAmount)< -999999999L) {

                            vdGetCSTCurSymbol(szCurSym);
                            inNegPos=strlen(szCurSym);
                            srRcpt.unFrm.srSummary.srMid.szNetTotal[inNegPos]='-';

                         }
            */ // KK commented it out to avoid two '-' symbols from the total.


            if (inPrintLines(pobPrinter, CPAC_DETAIL_TOTAL_START, CPAC_DETAIL_TOTAL_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
                return(VS_ERR);

            if (act_kbd_pending_test(KEY_CANCEL))
                return(VS_ESCAPE);

            /* Accumulate totals */




            lnGrandTotalCount += (int) (lnSaleCount + lnRefundCount + lnVoidSaleCount + lnVoidRefundCount);
            dbGrandSaleAmount += dbSaleAmount;
            dbGrandRefundAmount += dbRefundAmount;
            dbGrandVoidSaleAmount += dbVoidSaleAmount;
            dbGrandVoidRefundAmount += dbVoidRefundAmount;
            dbGrandTipAmount += dbTipAmount;



            //( lnSaleCount+lnRefundCount+lnVoidSaleCount+lnVoidRefundCount);


            inIssuerCnt++;
            if (inIssuerCnt > inGrandIssuerCnt)
                inGrandIssuerCnt = inIssuerCnt;
        }
    }
    inCloseAccum(&srDBFPtr);

#ifdef ICICI
	//venu_corrected to print the tiptotals in detail report if only one card range cards are swipped
	if(inIssuerCnt == 1)
	{
 inLoadTCTRec(0);
 if(inGetTipProcessing() ==1)
 	{
  		if(inPrintLines(&obPrinter, 55, 56, NO_BL_LINE, 0L) != VS_SUCCESS)
  		return(VS_ERR);
	}
}//}
    	/* Print Grand Totals if more than one issuer */
    	if (inIssuerCnt > 1)
	{
       	if (inGrandIssuerCnt > 1)
		{
#else
	/* Print Grand Totals if more than one issuer */
    	if (inIssuerCnt > 1)
	{
       	if (inGrandIssuerCnt > 1)
		{

#endif   /* ICICI  */
#if 0 /* LENIN */
    /* Set print line */
    sprintf(srRcpt.unFrm.srSummary.srMid.szCreditCount, SUBSTITUTE_D,
        srGrandTots/*[TOTAL_ISSUERS]*/.inTotalCnt);
    /* Total Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szCreditTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnTotalAmt);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCreditTotal);
    /* Sale Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szDebitTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnSaleAmt);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szDebitTotal);
    /*Tip Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnTipAmt);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szAdjustTotal);
    /*Tax Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szTaxTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnTaxAmt);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szTaxTotal);
    /*Surcharge Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnSurCharge);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);
    /*CashBack Amount */
    sprintf(srRcpt.unFrm.srSummary.srMid.szCashBackTotal, SUBSTITUTE_LD,
        srGrandTots/*[TOTAL_ISSUERS]*/.lnCashBack);
    vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCashBackTotal);
    /* Send VS_TRUE so FORM_FEED will print */
    #endif /* 0 */

            dbGrandTotalAmount = dbGrandSaleAmount - dbGrandRefundAmount;

            sprintf(srRcpt.unFrm.srSummary.srMid.szCreditCount, SUBSTITUTE_LD, lnGrandSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szDebitCount, SUBSTITUTE_LD, lnGrandRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustCount, SUBSTITUTE_LD, lnGrandVoidSaleCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szReversalCount, SUBSTITUTE_LD, lnGrandVoidRefundCount);
            sprintf(srRcpt.unFrm.srSummary.srMid.szNetCount, SUBSTITUTE_LD, lnGrandTotalCount);

            vdDb2Str(dbGrandSaleAmount, srRcpt.unFrm.srSummary.srMid.szCreditTotal);
            vdDb2Str(dbGrandRefundAmount, srRcpt.unFrm.srSummary.srMid.szDebitTotal);
            vdDb2Str(dbGrandVoidSaleAmount, srRcpt.unFrm.srSummary.srMid.szAdjustTotal);

            vdDb2Str(dbGrandVoidRefundAmount, srRcpt.unFrm.srSummary.srMid.szReversalTotal);
            vdDb2Str(dbGrandTotalAmount, srRcpt.unFrm.srSummary.srMid.szNetTotal);
            vdDb2Str(dbGrandTipAmount, srRcpt.unFrm.srSummary.srMid.szCashBackTotal);
            //vdDb2Str(dbGrandOfflineAmount,srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal);

            /*  sprintf(srRcpt.unFrm.srSummary.srMid.szCreditTotal, SUBSTITUTE_LD, lnGrandSaleAmount);
                       sprintf(srRcpt.unFrm.srSummary.srMid.szDebitTotal, SUBSTITUTE_LD, lnGrandRefundAmount);
                       sprintf(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, SUBSTITUTE_LD, lnGrandVoidSaleAmount);
                       sprintf(srRcpt.unFrm.srSummary.srMid.szReversalTotal, SUBSTITUTE_LD, lnGrandVoidRefundAmount);
                       sprintf(srRcpt.unFrm.srSummary.srMid.szNetTotal, SUBSTITUTE_LD, lnGrandTotalAmount);
            */
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCreditTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szDebitTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szReversalTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szNetTotal, VS_TRUE);
            vdFormatAmount(srRcpt.unFrm.srSummary.srMid.szCashBackTotal, VS_TRUE);

            if ((dbGrandSaleAmount - dbGrandRefundAmount) < -999999999999.00) {
                strcpy(szCurSym, szGetCurSymbol());
                inNegPos = strlen(szCurSym);
                srRcpt.unFrm.srSummary.srMid.szNetTotal[inNegPos] = '-';
            }

            // vdCPACSetSummaryBottomCondition (pobTran, VS_TRUE, &srGrandTots/*[TOTAL_ISSUERS]*/);
                if(inGetTipProcessing() == 0)
                	{
            if (inPrintLines(pobPrinter, CPAC_TOTAL_LABEL_START, CPAC_TOTAL_LABEL_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
                return(VS_ERR);
                	}
		else
			if (inPrintLines(pobPrinter, CPAC_TOTAL_LABEL_START, 56, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
                return(VS_ERR);
            // if(inPrintLines(pobPrinter, DETAIL_FORM_FEED, DETAIL_BOTTOM_END, NO_BL_LINE, 0x80000000) != VS_SUCCESS)
            //   return(VS_ERR);
        }
    }
    if (inPrintLines(pobPrinter, CPAC_EMPTY_LINE_START, CPAC_EMPTY_LINE_END, 0, 0L) != VS_SUCCESS)
        return (VS_ERR);

    if (inPrintLines(pobPrinter, CPAC_END_OF_REPORT_START, CPAC_END_OF_REPORT_END, NO_BL_LINE, 0x80000000) != VS_SUCCESS)
        return(VS_ERR);
	LOG_PRINTFF((0x08L, "==inImamCPACPrintDetailGrandTotal== END"));
    return(VS_SUCCESS);
}


/******************************************************************************
* @func int | inCITIFlowPrintReceipt |
*       Transaction flow function to print the receipt
*
* @parm TRANSACTION_OBJECT *| pobTran
*       Transaction object
*
* @rdesc return values.
* @flag int    |  VS_ERR
* @flag int    |  VS_SUCCESS
* @end
*******************************************************************************/


int inCITIFlowPrintReceipt(TRANSACTION_OBJECT* pobTran) {
    int inRetval;
    int inPrintOption;

    if (!fGetPrintReceipt(pobTran))
        return(VS_SUCCESS);

    if (!fGetTRTf3(pobTran) && !fGetTRTf2(pobTran) && !fGetTRTf1(pobTran))
        return(VS_SUCCESS);

    /* if the transaction is FPS qualified and the print option is prompt,
        prompt user if customer receipt should be printed */
    if ((pobTran->srBRec.inPrintOption == PRT_PROMPT) && fFPSQualified(pobTran)) {

	if (fCPACCustomerCopyReceipt(pobTran))
            pobTran->srBRec.inPrintOption = PRT_BANK;
        else
            pobTran->srBRec.inPrintOption = PRT_NONE;
    }

    if (pobTran->srBRec.inPrintOption == PRT_NONE)
        return(VS_SUCCESS);

    inPrintOption = pobTran->srBRec.inPrintOption;
	//#ifdef ICICI   // jrd
	/*ATS Bug #6*/
	vdSGErrorMessage(0L);
	vdSGRespMsg("");
	/*ATS Bug #6*/
	//#endif  /*  ICICI   */

    if (vPFRSetPartFunc(__LINE__)) {
        /* Store the print both or single receipt option - this is lost if power fails while printing
            REMEMBER- This will not occur if we are in a recovery state */
        inAddExternalPfrData(PFR_PRINT_BOTH, (unsigned char *) &inPrintOption, sizeof(int));
    } else
        inGetExternalPfrData(PFR_PRINT_BOTH, (unsigned char *) &inPrintOption, sizeof(int));


    /* Set the power failure recovery state to just before receipt printing begin */
    if ((uinCurrentState != CITI_PFR_BEGIN_CUST_PRINTING_RECEIPT) && (uinCurrentState != CITI_PFR_BEGIN_BANK_PRINTING_RECEIPT)) {
        inPFRStateStoreAll(PFR_BEGIN_PRINTING_RECEIPT, pobTran, 1, 1);
        if (fGetTRTf3(pobTran)) {
            pobTran->srBRec.inPrintOption = PRT_MERCH;
            if ((inRetval = inRunFormSegments(pobTran, BASE_RECEIPT)) != VS_ERR) {
#ifdef CITI_PHIL
                inPFRStateStoreAll(CITI_PFR_BEGIN_BANK_PRINTING_RECEIPT, pobTran, 1, 1);
                if (fGetTRTf1(pobTran) && fCITICustomerReceipt(pobTran)) {
                    pobTran->srBRec.inPrintOption = PRT_BANK;
                    inRetval = inRunFormSegments(pobTran, BASE_RECEIPT);
                }
#endif /* CITI_PHIL */
				inPFRStateStoreAll(CITI_PFR_BEGIN_CUST_PRINTING_RECEIPT, pobTran, 1, 1);
                if (fGetTRTf2(pobTran) && fCPACCustomerCopyReceipt(pobTran)) {
                    pobTran->srBRec.inPrintOption = PRT_CUST;
                    inRetval = inRunFormSegments(pobTran, BASE_RECEIPT);
                }
            }
        } else {
            inPFRStateStoreAll(CITI_PFR_BEGIN_BANK_PRINTING_RECEIPT, pobTran, 1, 1);
            if (fGetTRTf1(pobTran) && fCITICustomerReceipt(pobTran)) {
                pobTran->srBRec.inPrintOption = PRT_BANK;
                inRetval = inRunFormSegments(pobTran, BASE_RECEIPT);
            }
            inPFRStateStoreAll(CITI_PFR_BEGIN_CUST_PRINTING_RECEIPT, pobTran, 1, 1);
            if (fGetTRTf2(pobTran) && fCPACCustomerCopyReceipt(pobTran)) {
                pobTran->srBRec.inPrintOption = PRT_CUST;
                inRetval = inRunFormSegments(pobTran, BASE_RECEIPT);
            }
		}
    } else {
        pobTran->srBRec.inPrintOption = inPrintOption;
        inPFRStateStoreAll(CITI_PFR_BEGIN_CUST_PRINTING_RECEIPT, pobTran, 1, 1);
        if (uinCurrentState == CITI_PFR_BEGIN_CUST_PRINTING_RECEIPT) {
            if (fGetTRTf2(pobTran) && fCPACCustomerCopyReceipt(pobTran)) {
                pobTran->srBRec.inPrintOption = PRT_CUST;
                inRetval = inRunFormSegments(pobTran, BASE_RECEIPT);
                inPFRStateStoreAll(CITI_PFR_BEGIN_BANK_PRINTING_RECEIPT, pobTran, 1, 1);
            }
        }
#ifdef CITI_PHIL
        if (fGetTRTf1(pobTran) && fCITICustomerReceipt(pobTran)) {
            pobTran->srBRec.inPrintOption = PRT_BANK;
            inRetval = inRunFormSegments(pobTran, BASE_RECEIPT);
        }
#endif /* CITI_PHIL */
    }


    /* The receipt has been printed, we can now return to an idle state */
    inPFRStateStoreAll(PFR_IDLE_STATE, pobTran, 0, 0);


    uinCurrentState = 0;
    pobTran->srTRTRec.PrintReceipt = VS_FALSE;

#ifdef SHELL_FLEET
    memset(szKbdBuf, NULL_CH, CARD_SIZE);
#endif
//jrd spqalog023 spqalog043 
//if(inRetval==VS_ERR) // Disable it
//{
//	inRunFunction(pobTran, CITI_END_MODEM);
//
	return (VS_SUCCESS); //
    //return (inRetval);
}

/******************************************************************************
* @func VS_BOOL | fCITICustomerReceipt |
*       Determine if customer receipt should be printed by prompting
*                    the user.
*
* @parm TRANSACTION_OBJECT *| pobTran
*       Transaction object
*
* @rdesc return values.
* @flag int    |  VS_TRUE
* @flag int    |  VS_FALSE
* @end
*******************************************************************************/

VS_BOOL fCITICustomerReceipt(TRANSACTION_OBJECT* pobTran) {
    int inRetVal = VS_FALSE;
    signed char chAnswer;
    int inGrid,
    inChiLen,
    inHalfLen,
    inFontType;
    char szChiMsgBuffer[DISP_STR_LEN + 1];
    char szChiMsgBuffer_Part1[DISP_STR_LEN + 1];
    char szChiMsgBuffer_Part2[DISP_STR_LEN + 1];

    //chAnswer = (char) obDisp.inDO_ChooseOne(NULL,(char *)pchGetMsg(CITI_BANK_COPY_MSG), (char *)pchGetMsg(YESNO_MSG5x), 2, NULL_PFI);

	if (!fGetImamPrintPrompt()) { //
		pause(300);
		return (VS_TRUE);
	}

    inGrid = getgrid();
    inFontType = get_font_mode();

    if (inGrid == 0)  //16 0r 8 chars
    {
        //Chinese version
        memset(szChiMsgBuffer, NULL_CH, sizeof(szChiMsgBuffer));
        vdGetMessageFromFile(CITI_BANK_COPY_MSG, szChiMsgBuffer);
        inChiLen = strlen(szChiMsgBuffer) / inFontType;
        inHalfLen = ((int) ((inChiLen + 1) / 2)) * 2; //In order to have a longer half in upper and shorter half in lower

        memset(szChiMsgBuffer_Part1, NULL_CH, sizeof(szChiMsgBuffer_Part1));
        strncpy(szChiMsgBuffer_Part1, szChiMsgBuffer, inHalfLen);
        memset(szChiMsgBuffer_Part2, NULL_CH, sizeof(szChiMsgBuffer_Part2));
        strncpy(szChiMsgBuffer_Part2, szChiMsgBuffer + inHalfLen, (strlen(szChiMsgBuffer) - inHalfLen));

        //Kelvin_F2 --- start: clean non-status line before display confirm message
        vdClearNonTitleLines();
        //Kelvin_F2 --- end: clean non-status line before display confirm message
        vdDisplayAt(1, 2, szChiMsgBuffer_Part1, NO_CLEAR);
        vdDisplayAt(1, 3, szChiMsgBuffer_Part2, NO_CLEAR);

        chAnswer = (char) obDisp.inDO_ChooseOne(NULL, NULL, (char *) pchGetMsg(YESNO_MSG5x), 2, NULL_PFI);
    } else {
        //English version
        chAnswer = (char) obDisp.inDO_ChooseOne(NULL, (char *) pchGetMsg(CITI_BANK_COPY_MSG), (char *) pchGetMsg(YESNO_MSG5x), 2, NULL_PFI);
    }

    if (chAnswer == KEY_YES)
        inRetVal = VS_TRUE;

    return (inRetVal);
}

//Kelvin_F2 --- start: display correct "print customer receipt in Chin"
/*********************************************************************************************
* @func static VS_BOOL | fCPACCustomerCopyReceipt |
*       Determine if customer receipt should be printed by prompting
*                    the user.
*
* @parm TRANSACTION_OBJECT *| pobTran
*       Transaction object
*
* @rdesc return values.
* @flag int    |  VS_TRUE
* @flag int    |  VS_FALSE
* @end
**********************************************************************************************/
VS_BOOL fCPACCustomerCopyReceipt(TRANSACTION_OBJECT* pobTran) {
    int inRetVal = VS_FALSE;
    signed char chAnswer;

    int inGrid,
    inChiLen,
    inHalfLen,
    inFontType;
    char szChiMsgBuffer[DISP_STR_LEN + 1];
    char szChiMsgBuffer_Part1[DISP_STR_LEN + 1];
    char szChiMsgBuffer_Part2[DISP_STR_LEN + 1];

    inGrid = getgrid();
    inFontType = get_font_mode();

	if (!fGetImamPrintPrompt()) { //
		pause(300);
		return (VS_TRUE);
	}

    if (inGrid == 0)  //16 0r 8 chars
    {
        //Chinese version
        memset(szChiMsgBuffer, NULL_CH, sizeof(szChiMsgBuffer));
        vdGetMessageFromFile(PRINT_MERCH_COPY_MSG, szChiMsgBuffer);
        inChiLen = strlen(szChiMsgBuffer) / inFontType;
        inHalfLen = ((int) ((inChiLen + 1) / 2)) * 2; //In order to have a longer half in upper and shorter half in lower

        memset(szChiMsgBuffer_Part1, NULL_CH, sizeof(szChiMsgBuffer_Part1));
        strncpy(szChiMsgBuffer_Part1, szChiMsgBuffer, inHalfLen);
        memset(szChiMsgBuffer_Part2, NULL_CH, sizeof(szChiMsgBuffer_Part2));
        strncpy(szChiMsgBuffer_Part2, szChiMsgBuffer + inHalfLen, (strlen(szChiMsgBuffer) - inHalfLen));
#ifndef  TLFB

        vdClearNonTitleLines();
        vdDisplayAt(1, 2, szChiMsgBuffer_Part1, NO_CLEAR);
        vdDisplayAt(1, 3, szChiMsgBuffer_Part2, NO_CLEAR);
#else
        vdClearNonTitleLines();

        vdDisplayAt(1, 2, szChiMsgBuffer, NO_CLEAR);

#endif /* TLFB */
        chAnswer = (char) obDisp.inDO_ChooseOne(NULL, NULL, (char *) pchGetMsg(YESNO_MSG5x), 2, NULL_PFI);
    } else {
        //English version
        // Rannie_B1 10052004: Fixed the bug wherein the card label is being overwritten by the Yes/No window
        // during the printing of receipt copies
        vdDisplayTranTitle(pobTran->srBRec.lnMessage);
	// End Rannie_B1 10052004
        chAnswer = (char) obDisp.inDO_ChooseOne(NULL, (char *) pchGetMsg(PRINT_MERCH_COPY_MSG), (char *) pchGetMsg(YESNO_MSG5x), 2, NULL_PFI);
    }

    if (chAnswer == KEY_YES)
        inRetVal = VS_TRUE;

    return (inRetVal);
}
//Kelvin_F2 --- end: display correct "print customer receipt in Chin"

//Kelvin_F2 --- start: support Chinese/English display language function
/*********************************************************************************************
* @func void | vdCPACDisplayNoDataMsg|
*       Displays msg "No Data - " + host name
*
* @parm TRANSACTION_OBJECT * | pobTran |
*       Transaction object.
*
* @rdesc return values - None.
* @end
**********************************************************************************************/
void vdCPACDisplayNoDataMsg() {
    char szDummy[MESSAGE_SIZE];
    char szHostName[HOST_NAME_SIZE + 1];

    vdGetMessageFromFile(NO_SETT_DATA_MSG, szDummy);
    strcpy(szHostName, szGetHostName());


    if ((get_font_mode() == 2) && (getgrid() == 0)) {
        char szTemp[10];
        strcat(szTemp, szHostName);
        vdDisplayAt(obDisp.inHomeCol, obDisp.inStatusLine, szDummy, CLR_EOL);
        inMLDisplayAt((strlen(szDummy) + 1), obDisp.inStatusLine, szTemp, CLR_EOL, ML_USE_GIVEN_FONT, ML_MENU_FONT, ASC4X16_VFT);
    } else {
        strcat(szDummy, szHostName);
        vdDisplayMessage(szDummy, WARNING_MSG);
    }
}
//Kelvin_F2 --- end: support Chinese/English display language function

//Kelvin_F2 --- start: reprint settlement report
/*********************************************************************************************
* @func int | inCPACRePrintSettlementReport|
*       Form flow function which Browes through the batch and
*       prints the settlement report
*
* @parm TRANSACTION_OBJECT * | pobTran |
*       Transaction object.
*
* @rdesc return values.
* @flag int    |  VS_ERR
* @flag int    |  VS_SUCCESS
* @end
**********************************************************************************************/

int inCPACRePrintSettlementReport(TRANSACTION_OBJECT* pobTran) {
    char szDate[DATE_SIZE + 1];
    long lnRecNum,
    lnRecCnt;
    int inHostIndex; //Kelvin_f2 --- fix "No invoice#" error
    SETT_REC srLocSRec;
    SETT_KEY srLocSKey;

    inHostIndex = inGetHostHandle();            //Kelvin_f2 --- fix "No invoice#" error
    inGlobalHostHandle = inGetHostHandle();   //Kelvin_f2 --- fix "No invoice#" error

    strcpy(srRcpt.szHostName, szGetHostName());
    strcpy(szDate, pobTran->szSettDate);

    if (szDate[0] == '\0' && pobTran->szBatchNum[0] == '\0') {
        lnRecCnt = lnGetSettRecCnt();

        if (lnRecCnt == 0L) {
            vdCPACDisplayNoDataMsg();
            return(VS_SUCCESS);
        }

        /* get all records for host and print   */
        for (lnRecNum = 0L; lnRecNum < lnRecCnt; lnRecNum++) {
            if (inLoadSettRec(pobTran, &srLocSRec, &srLocSKey, lnRecNum) == VS_SUCCESS) {
                strlcpy(pobTran->szSettDate, &srLocSRec.szDate[4], 2);
                strlcpy(&pobTran->szSettDate[2], srLocSRec.szDate, 4);
                strlcpy(pobTran->szSettTime, srLocSRec.szTime, 6);
                vdLoadDateTime(pobTran);
                strcpy(srRcpt.szBatchNum, srLocSRec.szBatchNum);
                pad(srRcpt.szBatchNum, srRcpt.szBatchNum, '0', inGetBatchNumSize(), RIGHT);
                strcpy(srRcpt.szStatusMessage, srLocSRec.szSettleResp);
                vdFormatSettleStatusMsg(srRcpt.szStatusMessage);

                if (lnRecNum == 0L)
                    inPrintReceiptHeader(pobTran);
                else
                    lnMiddleCondition &= 0xEFFFFFFF;    /* Do not print report title but once   */
                if (lnRecNum == lnRecCnt - 1)
                    lnMiddleCondition |= 0x04000000;    /* Eject paper after print */
                if (inPrintLines(&obPrinter, CPAC_SUMMARY_TOP_START, CPAC_SUMMARY_MIDDLE_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
                    return(VS_ERR);
                //Print settlement successful or not
                if (inPrintLines(&obPrinter, CPAC_SETTLEMENT_STATUS_START, CPAC_SETTLEMENT_STATUS_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
                    return(VS_ERR);
                if (inPrintLines(&obPrinter, CPAC_FORM_FEED_START, CPAC_FORM_FEED_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
                    return(VS_ERR);
            } else {
                if (lnRecNum == 0L) {
                    vdCPACDisplayNoDataMsg();
                    return(VS_SUCCESS);
                }
                break;          /* no more records  */
            }
        }
    } else {
        if (szDate[0] != '\0') {
            if (inGetDateSettRec(pobTran, &srLocSRec, &srLocSKey, &lnRecNum) != VS_SUCCESS) {
                vdCPACDisplayNoDataMsg();
                return(VS_SUCCESS);
            }
            strlcpy(pobTran->szSettDate, &srLocSRec.szDate[4], 2);
            strlcpy(&pobTran->szSettDate[2], srLocSRec.szDate, 4);
            strlcpy(pobTran->szSettTime, srLocSRec.szTime, 6);
            vdLoadDateTime(pobTran);
            strcpy(srRcpt.szBatchNum, srLocSRec.szBatchNum);
            pad(srRcpt.szBatchNum, srRcpt.szBatchNum, '0', inGetBatchNumSize(), RIGHT);
            // Load Settle Response Message.
            strcpy(srRcpt.szStatusMessage, srLocSRec.szSettleResp);
            vdFormatSettleStatusMsg(srRcpt.szStatusMessage);
            inPrintReceiptHeader(pobTran);
            if (inPrintLines(&obPrinter, CPAC_SUMMARY_TOP_START, CPAC_SUMMARY_MIDDLE_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
                return(VS_ERR);

            //Print the settlement successful or not
            if (inPrintLines(&obPrinter, CPAC_SETTLEMENT_STATUS_START, CPAC_SETTLEMENT_STATUS_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
                return(VS_ERR);

            lnMiddleCondition &= 0xEFFFFFFF;    /* Do not print report title but once   */
            for (lnRecNum += 1L; lnRecNum < 7L; lnRecNum++) {
                if (inLoadSettRec(pobTran, &srLocSRec, &srLocSKey, lnRecNum) == VS_SUCCESS) {
                    strlcpy(pobTran->szSettDate, &srLocSRec.szDate[4], 2);
                    strlcpy(&pobTran->szSettDate[2], srLocSRec.szDate, 4);
                    strlcpy(pobTran->szSettTime, srLocSRec.szTime, 6);
                    vdLoadDateTime(pobTran);
                    strcpy(srRcpt.szBatchNum, srLocSRec.szBatchNum);
                    pad(srRcpt.szBatchNum, srRcpt.szBatchNum, '0', inGetBatchNumSize(), RIGHT);
                    strcpy(srRcpt.szStatusMessage, srLocSRec.szSettleResp);
                    vdFormatSettleStatusMsg(srRcpt.szStatusMessage);

                    if (strcmp(srLocSRec.szDate, szDate) == 0) {
                        if (inPrintLines(&obPrinter, CPAC_SUMMARY_TOP_START, CPAC_SUMMARY_MIDDLE_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
                            return(VS_ERR);

                        //Print the settlement successful or not
                        if (inPrintLines(&obPrinter, CPAC_SETTLEMENT_STATUS_START, CPAC_SETTLEMENT_STATUS_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
                            return(VS_ERR);
                    }
                }
            }
            /* Prevent double printing status message */
            if (inPrintLines(&obPrinter, CPAC_FORM_FEED_START, CPAC_FORM_FEED_END, NO_BL_LINE, 0x04000000) != VS_SUCCESS)
                return(VS_ERR);
        }
        if (pobTran->szBatchNum[0] != '\0') {
            if (inGetBatchNumSettRec(pobTran, &srLocSRec, &srLocSKey) != VS_SUCCESS) {
                vdCPACDisplayNoDataMsg();
                return(VS_SUCCESS);
            }
            strlcpy(pobTran->szSettDate, &srLocSRec.szDate[4], 2);
            strlcpy(&pobTran->szSettDate[2], srLocSRec.szDate, 4);
            strlcpy(pobTran->szSettTime, srLocSRec.szTime, 6);
            vdLoadDateTime(pobTran);
            strcpy(srRcpt.szBatchNum, srLocSRec.szBatchNum);
            pad(srRcpt.szBatchNum, srRcpt.szBatchNum, '0', inGetBatchNumSize(), RIGHT);
            /* Load Settle Response Message. */
            strcpy(srRcpt.szStatusMessage, srLocSRec.szSettleResp);
            vdFormatSettleStatusMsg(srRcpt.szStatusMessage);
            inPrintReceiptHeader(pobTran);
            lnMiddleCondition |= 0x04000000;    /* Eject paper after print */
            if (inPrintLines(&obPrinter, CPAC_SUMMARY_TOP_START, CPAC_SUMMARY_MIDDLE_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
                return(VS_ERR);

            //Print the settlement successful or not
            if (inPrintLines(&obPrinter, CPAC_SETTLEMENT_STATUS_START, CPAC_SETTLEMENT_STATUS_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
                return(VS_ERR);

            if (inPrintLines(&obPrinter, CPAC_END_OF_REPORT_START, CPAC_END_OF_REPORT_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
                return(VS_ERR);
        }
    }
    vdSGErrorMessage(0L);
    return(VS_SUCCESS);
}
//Kelvin_F2 --- end: Reprint settlement report

//Kelvin_F2 --- start: Chinese tran code printing
#ifdef HKGM
void vdHKGMSetTranCodeCondition(TRANSACTION_OBJECT* pobTran) {
    int fNewTranCode = 0; // 1= have new tran code

    if ((pobTran->srBKey.fVoided == VS_TRUE) || (pobTran->srBRec.inNumberOfAdjusts > 0) || (pobTran->srBRec.inNumberOfTipAdjusts > 0))
        fNewTranCode = 1;

    lnHeaderCondition = formater_set_flags(0, 0, 
		((pobTran->inTransactionCode == SALE_OFFLINE) || 
		 ((inGGOpCode() == REPRINT_ANY_OPERATION) && (fNewTranCode == 0) && (pobTran->srBRec.inCode == SALE_OFFLINE)) || 
		 ((inGGOpCode() == REPRINT_LAST_OPERATION) && (pobTran->srBRec.inOrgCode == SALE_OFFLINE))), 
		((pobTran->inTransactionCode == SALE) || 
		 ((inGGOpCode() == REPRINT_ANY_OPERATION) && (fNewTranCode == 0) && (pobTran->srBRec.inCode == SALE)) || 
		 ((inGGOpCode() == REPRINT_LAST_OPERATION) && (pobTran->srBRec.inOrgCode == SALE))), 
		0, 0, 
		((pobTran->inTransactionCode == AUTH_ONLY || pobTran->inTransactionCode == IMAM_CARDVER) || 
		 ((inGGOpCode() == REPRINT_ANY_OPERATION) && (fNewTranCode == 0) && (pobTran->srBRec.inCode == AUTH_ONLY || pobTran->srBRec.inCode == IMAM_CARDVER)) || 
		 ((inGGOpCode() == REPRINT_LAST_OPERATION) && (pobTran->srBRec.inOrgCode == AUTH_ONLY))), 
		((pobTran->inTransactionCode == REFUND) || ((inGGOpCode() == REPRINT_ANY_OPERATION) && (fNewTranCode == 0) && (pobTran->srBRec.inCode == REFUND)) || ((inGGOpCode() == REPRINT_LAST_OPERATION) && (pobTran->srBRec.inOrgCode == REFUND))), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ((pobTran->inTransactionCode == VOID) || ((inGGOpCode() == REPRINT_ANY_OPERATION) && (fNewTranCode == 1) && (pobTran->srBKey.fVoided == VS_TRUE)) || ((inGGOpCode() == REPRINT_LAST_OPERATION) && (fNewTranCode == 1) && (pobTran->srBKey.fVoided == VS_TRUE))), 0, 0, 0, ((pobTran->inTransactionCode == TIP_ADJUST) || ((inGGOpCode() == REPRINT_ANY_OPERATION) && (fNewTranCode == 1) && (pobTran->srBRec.inNumberOfTipAdjusts > 0)) || ((inGGOpCode() == REPRINT_LAST_OPERATION) && (fNewTranCode == 1) && (pobTran->srBRec.inNumberOfTipAdjusts > 0))),

                        0,
                        0,
                        0,
                        ((pobTran->inTransactionCode == ADJUST) || ((inGGOpCode() == REPRINT_ANY_OPERATION) && (fNewTranCode == 1) && (pobTran->srBRec.inNumberOfAdjusts > 0)) || ((inGGOpCode() == REPRINT_LAST_OPERATION) && (fNewTranCode == 1) && (pobTran->srBRec.inNumberOfAdjusts > 0))),


                        0,
                        0,
                        ((pobTran->inTransactionCode == PRE_AUTH) || ((inGGOpCode() == REPRINT_ANY_OPERATION) && (fNewTranCode == 0) && (pobTran->srBRec.inCode == PRE_AUTH)) || ((inGGOpCode() == REPRINT_LAST_OPERATION) && (pobTran->srBRec.inOrgCode == PRE_AUTH))),
                        ((pobTran->inTransactionCode == PRE_COMP) || ((inGGOpCode() == REPRINT_ANY_OPERATION) && (fNewTranCode == 0) && (pobTran->srBRec.inCode == PRE_COMP)) || ((inGGOpCode() == REPRINT_LAST_OPERATION) && (pobTran->srBRec.inOrgCode == PRE_COMP))), -1);
}
#endif /* HKGM */
//Kelvin_F2 --- end: chinese tx code printing

int inCPACPrintReceiptTop(TRANSACTION_OBJECT* pobTran) {
#ifndef IMAM_REMOVE
    LOG_PRINTFF((0x8L, "Print start"));
    if (pobTran->fPreprinted)
        return(VS_SUCCESS);

    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }
    if (!pobTran->srTRTRec.PrintReceipt && !(pobTran->srBRec.inPrintOption & PRT_DUPLICATE))
        return(VS_SUCCESS);

    if (((inGGCode() == PRE_COMP) && (!fPrintCloseTab(pobTran))) || ((inGGCode() == PRE_AUTH) && (fGetOpenTabOptRec() == VS_FALSE))) {
        vdDisplayMessageFromFile(NO_RCPT_ERR_MSG, WARNING_MSG);
        pause(50);
        return(VS_SUCCESS);
    }

    if (fGetEnablePrinter())
        vdDisplayMessageFromFile(PRINTING_MSG, STATUS_MSG);

    /*
        Preprint up to account number
    */

    inPrintReceiptHeader(pobTran);

    /* LENIN CPAC #if TBD_CPAC */
    vdSetPrintReceiptConditions(pobTran);
    /* LENIN CPAC #endif  CPAC_TBD */

    /*LENIN CPAC  #if TBD_CPAC */
    vdMakeReceiptTop(pobTran);
    /* LENIN #endif  CPAC_TBD */

    vdCPACMakeReceiptAfterResp(pobTran);
    pad(srRcpt.unFrm.srReceipt.szSTAN, srRcpt.unFrm.srReceipt.szSTAN, '0', 6, RIGHT);
    pad(srRcpt.szInvNum, srRcpt.szInvNum, '0', 6, RIGHT);  // Inv_num padding CPAC_CITI_PHIL

#ifdef CITI_PHIL
    //Kelvin_F2 --- start: no need to mask MID
#ifdef MASK_TID_AND_MID
    vdMaskCitiMTID();
#endif
    //Kelvin_F2 --- end: no need to mask MID
#endif /* CITI_PHIL */

    /* LENIN CPAC #if TBD_CPAC */
    inPrintReceiptHeader2(&obPrinter, pobTran);
    /* LENIN CPAC #endif  CPAC_TBD */

    pobTran->fPreprinted = VS_TRUE;


    ///*Saritha_b1.............Start...........Amex Roc Printing */
    //#ifdef AMEX_SOC

    //  strcpy(srRcpt.unFrm.srReceipt.szGenBuf2, (char*)srISO.pszField62);

    //if (inPrintLines(&obPrinter, AMEX_SOC_PRINT_START, AMEX_SOC_PRINT_END, NO_BL_LINE, 0L) != VS_SUCCESS)
    //  return(VS_ERROR);

    //#endif  /*   AMEX_ROC */

    /*Saritha_b1.............End...........Amex Roc Printing */
#endif //IMAM_REMOVE
    return(VS_SUCCESS);
}


/*-------------------------------------------------------------------------
    Function :    vdMakeReceiptTop
    Description :
    Parameters :
    Returns :
    Notes :
--------------------------------------------------------------------------*/

void vdMakeReceiptTop (TRANSACTION_OBJECT *pobTran)

{
    char szExpDate[EXP_DATE_SIZE + 1];
    char  room[ROOM_NUM_SIZE + 1];
    char szTransName[MESSAGE_SIZE + 1];
    char AdjTipAdjFlag;

    memset(srRcpt.szClerkId,'\0',sizeof(srRcpt.szClerkId));

    if(inGetClerkMode() != NO_CLERK)
        strlcpy(srRcpt.szClerkId, pobTran->srBKey.szClerkId, CLERK_ID_SIZE);

    memset(srRcpt.szTransName,'\0',sizeof(srRcpt.szTransName));

    chGetCPACAdjTipAdjflag (&pobTran->srBRec, (unsigned char *)&AdjTipAdjFlag);


    if (pobTran->srBRec.lnMessage)              /* mb1 */
        vdCPACGetMessageFromReceiptFile(pobTran->srBRec.lnMessage, szTransName,pobTran);
    if (pobTran->srBKey.fVoided == VS_TRUE)
    {
        vdCPACGetMessageFromReceiptFile(VOID_MSG6, srRcpt.szTransName,pobTran);
        pad(srRcpt.szTransName, srRcpt.szTransName, ' ', strlen(srRcpt.szTransName) + 1, LEFT);
    }
    else
    {
    	if((pobTran->inOperationCode == BATCH_REVIEW_OPERATION)||(pobTran->inTransactionCode == ADJUST)||
    		(pobTran->inTransactionCode==CPAC_PHIL_ADJUST)||(pobTran->inTransactionCode == TIP_ADJUST))

    	{
    	       //originally if(pobTran->fAdjust)
		if(pobTran->fAdjust||((AdjTipAdjFlag=='A')&&(pobTran->inTransactionCode != TIP_ADJUST)) )
			vdCPACGetMessageFromReceiptFile(ADJUST_MSG6, srRcpt.szTransName,pobTran);

		else
			//originally if(pobTran->fTipAdjust)
			if(pobTran->fTipAdjust||((AdjTipAdjFlag=='T')&&(pobTran->inTransactionCode != ADJUST)))
				vdCPACGetMessageFromReceiptFile(CPAC_TIP_ADJUST_MSG, srRcpt.szTransName,pobTran);
		pad(srRcpt.szTransName, srRcpt.szTransName, ' ', strlen(srRcpt.szTransName) + 1, LEFT);
    	}
    	else
    	{
		if (pobTran->srBRec.inNumberOfAdjusts > 0 ||
		        pobTran->srBRec.inNumberOfTipAdjusts > 0 )
		{
		       if((pobTran->srBRec.inNumberOfAdjusts > 0)&& (AdjTipAdjFlag=='A'))
		       	vdCPACGetMessageFromReceiptFile(ADJUST_MSG6, srRcpt.szTransName,pobTran);
	       	else
	       		if((pobTran->srBRec.inNumberOfTipAdjusts > 0)&& (AdjTipAdjFlag=='T'))
       			vdCPACGetMessageFromReceiptFile(CPAC_TIP_ADJUST_MSG, srRcpt.szTransName,pobTran);

		        pad(srRcpt.szTransName, srRcpt.szTransName, ' ', strlen(srRcpt.szTransName) + 1, LEFT);
    		}
    	}
    }

#ifdef ICICI
  	if((pobTran->srTRTRec.TransactionCode== CASH_ADV) || (pobTran->srBRec.inCode== CASH_ADV))
    	{
    	 	vdCPACGetMessageFromReceiptFile(CASH_ADV_TRT_MSG, srRcpt.szTransName,pobTran);
    	}
  	else
    		strcat(srRcpt.szTransName, szTransName);

	if((pobTran->srBRec.inCode== CASH_ADV) && (pobTran->srBRec.inOrgCode == VOID))
   	{
       	memset(srRcpt.szTransName,'\0', sizeof(srRcpt.szTransName));
		strcpy(srRcpt.szTransName, "VOID CASHADVANCE");
   	}

#else
	strcat(srRcpt.szTransName, szTransName);

#endif  /* ICICI  */


    /* Pad Trans Name so that inverse print will have black symetrical */
    if ((inGetPrinterType() == PRINTER_350))
    {
//Kelvin_F2 --- start: no space in front of tranname
#ifndef HKGM
        switch ( inGetP350ColMode() )
        {
            case COLUMN_TYPE_24:
                pad(srRcpt.szTransName, srRcpt.szTransName, ' ', 12, CENTER);
                break;
            case COLUMN_TYPE_32:
                pad(srRcpt.szTransName, srRcpt.szTransName, ' ', 16, CENTER);
                break;
            case COLUMN_TYPE_42:
                pad(srRcpt.szTransName, srRcpt.szTransName, ' ', 21, CENTER);
                break;
        }
#endif /* HKGM */
//Kelvin_F2 --- end: no space in front of tranname
    }
    else {
        //pad(srRcpt.szTransName, srRcpt.szTransName, ' ', 21, CENTER); //LIEM : No Center Padding
		LOG_PRINTFF((0x08L, "srRcpt.szTransName : [%s]", srRcpt.szTransName));
	}

		strcpy(srRcpt.szHostName, szGetHostName());

    long2str (srRcpt.szBatchNum, lnGetBatchNum());
    pad (srRcpt.szBatchNum, srRcpt.szBatchNum, '0', inGetBatchNumSize(), RIGHT);

// vdDisplayAt(1,1,srRcpt.szBatchNum, CLR_EOL); get_char(); /* $$$ */
    strcpy(room, pobTran->srBRec.szRoomNum);

    if (strlen(room) > 0)
        strcpy(srRcpt.szInvNum,room);
    else
    if (pobTran->srBKey.fVoided || pobTran->fAdjust || pobTran->fTipAdjust ||
        (pobTran->srBRec.fCloseTabSameCard))
        sprintf(srRcpt.szInvNum, SUBSTITUTE_LD,pobTran->srBKey.lnInvNum);
    else
        sprintf(srRcpt.szInvNum, SUBSTITUTE_LD,pobTran->srBKey.lnInvNum);

    sprintf(srRcpt.unFrm.srReceipt.szSTAN, SUBSTITUTE_LD, pobTran->srBKey.lnOrgSTAN);
    sprintf(srRcpt.unFrm.srReceipt.szECRInvNo, SUBSTITUTE_LD, pobTran->lnECRInvNum);
	pad (srRcpt.szInvNum, srRcpt.szInvNum, '0', 6, RIGHT);  // CITI_PHIL added.


    memset(srRcpt.unFrm.srReceipt.szECRInvNo, 0, sizeof(srRcpt.unFrm.srReceipt.szECRInvNo));


	strcpy(srRcpt.unFrm.srReceipt.szServId,szGetSrvENum());
    //vdGetCDTSENum(srRcpt.unFrm.srReceipt.szServId); //CPAC2.1B

    if (strlen(pobTran->srBRec.szExpDate) > 0)
    {
        strcpy(szExpDate, pobTran->srBRec.szExpDate);
        sprintf(srRcpt.unFrm.srReceipt.szExpDate, "%.2s/%.2s", szExpDate+2, szExpDate);
    }

    //strcpy (srRcpt.unFrm.srReceipt.szCType,szGetIssuerLabel());
	strcpy (srRcpt.unFrm.srReceipt.szCType,szGetCardLabel());  //
    //vdGetIssuerLabel(srRcpt.unFrm.srReceipt.szCType);

    if (inGetHDTTotRecs() > 1)
       	strcpy(srRcpt.szHostName, szGetHostName());

    strcpy(srRcpt.unFrm.srReceipt.szCHolder, pobTran->srBRec.szCHolder);
    vdTrimSpaces(srRcpt.unFrm.srReceipt.szCHolder);

#ifdef SHIFT_DEFINED

    if (inGetShiftType() != NO_SHIFT)
        srRcpt.unFrm.srReceipt.chShift = pobTran->srBKey.chShift;
    else
        srRcpt.unFrm.srReceipt.chShift = '0';

#else
		srRcpt.unFrm.srReceipt.chShift = '0';

#endif
	{
		if (!strcmp((char *)srRcpt.szTransName, "Sale")){
			if(pobTran->srBRec.inTranCardType == DEBIT_CARD) {
				strcpy((char *)srRcpt.szTransName, "Debit");
			}
		}
		if (!strncmp((char *)srRcpt.szTransName, "Void", 4)){
			if (!strncmp((char *)srRcpt.szTransName, "Void Refund", 11)){
			} else {
				strcpy((char *)srRcpt.szTransName, "Void");
			}
		}
		if (pobTran->srTRTRec.TransactionCode == IMAM_PREAUTH_CANCEL) {
			strcpy((char *)srRcpt.szTransName, "PreAut Cncl");
		}
		if (pobTran->srTRTRec.TransactionCode == IMAM_PRECOMP_CANCEL) {
			strcpy((char *)srRcpt.szTransName, "Void PreCmp");
		}
	}
}



int inPrintReceiptHeader2(PRINTER_OBJECT* obPrinter,TRANSACTION_OBJECT* pobTran) {
    vdSetPrintHeaderCondition2(pobTran);
    if (inPrintLines(obPrinter, HEADER2_START, HEADER2_END, NO_BL_LINE, lnHeaderCondition) != VS_SUCCESS)
        return(VS_ERR);

    //Kelvin_F2 --- start: Chinese tx code printing
#ifdef HKGM
    vdHKGMSetTranCodeCondition(pobTran);
    if (inPrintLines(obPrinter, TRAN_CODE_LINE_START, TRAN_CODE_LINE_END, NO_BL_LINE, lnHeaderCondition) != VS_SUCCESS)
        return(VS_ERR);
#endif /*HKGM*/
    //Kelvin_F2 --- end: Chinese tx code printing

    return(VS_SUCCESS);
}



/*-------------------------------------------------------------------------
   Function :    vdSetPrintHeaderCondition2()
    Description :
    Parameters :
    Returns :
    Globals :
    Notes :
    Modification History :
      #     Date      Who                     Description
    ----- -------- ---------- ---------------------------------------------
      1   02/05/98 Betty_B1   Create
--------------------------------------------------------------------------*/

void vdSetPrintHeaderCondition2(TRANSACTION_OBJECT* pobTran) {
    int inTranCode;
    VS_BOOL inLenx;
    VS_BOOL fRedLine = VS_FALSE;
    VS_BOOL fBlackLine = VS_FALSE;

    /** /pdebug(("--vdSetPrintHeaderCondition2--"));*/

    if (inGetPrinterType() == NOPRINTER || !fGetEnablePrinter())
        return;

    if ((fRefundTrans(pobTran) || pobTran->srBKey.fVoided) && (inGetPrinterType() != PRINTER_350))
        fRedLine = VS_TRUE;
    else
        fBlackLine = VS_TRUE;

    inTranCode = inGGCode();
    inLenx = fGetDemoMode();

    lnHeaderCondition = formater_set_flags(((fRefundTrans(pobTran)) || pobTran->srBKey.fVoided),
		(fBlackLine && (fGetDemoMode())),
		(fRedLine && (fGetDemoMode())),
		(pobTran->srBRec.inPrintOption & PRT_DUPLICATE),
		(fRedLine),
		0,
		0,
		0,
		(fBlackLine && inGetApplicationType() == RETAIL && inGetClerkMode() != NO_CLERK && inGetShiftType() != NO_SHIFT),
		(fRedLine && inGetApplicationType() == RETAIL && inGetClerkMode() != NO_CLERK && inGetShiftType() != NO_SHIFT),
		(fBlackLine && inGetApplicationType() == RETAIL && inGetClerkMode() != NO_CLERK && inGetShiftType() == NO_SHIFT),
		(fRedLine && inGetApplicationType() == RETAIL && inGetClerkMode() != NO_CLERK && inGetShiftType() == NO_SHIFT),
		(fBlackLine && inGetApplicationType() == RESTAURANT && inGetClerkMode() != NO_CLERK && inGetShiftType() != NO_SHIFT),
		(fRedLine && inGetApplicationType() == RESTAURANT && inGetClerkMode() != NO_CLERK && inGetShiftType() != NO_SHIFT),
		(fBlackLine && inGetApplicationType() == RESTAURANT && inGetClerkMode() != NO_CLERK && inGetShiftType() == NO_SHIFT),
		(fRedLine && inGetApplicationType() == RESTAURANT && inGetClerkMode() != NO_CLERK && inGetShiftType() == NO_SHIFT),
		(fBlackLine && inGetClerkMode() == NO_CLERK && inGetShiftType() != NO_SHIFT),
		(fRedLine && inGetClerkMode() == NO_CLERK && inGetShiftType() != NO_SHIFT),
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		-1);


	// jrd 05112005 spqalog
	if (( pobTran->srBKey.fVoided==VS_TRUE)||(pobTran->srBRec.inCode == REFUND))
            lnHeaderCondition |= 0x80000000L;



    /* lnHeaderCondition =0;  LENIN CPAC
     if (fGetDemoMode()==VS_TRUE) {
            lnHeaderCondition | 0x00000002;
     }*/
}

//#ifdef HKGM
/*********************************************************************************************
* @func int | int inCPACStatReportOperation(TRANSACTION_OBJECT *pobTran) |
*
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
* @flag int    |  VS_SUCCESS    |
* @flag int    |  VS_ERR        |
* @end
**********************************************************************************************/


int inCPACStatReportOperation(TRANSACTION_OBJECT* pobTran) {
    int inFileDesc;
    signed int inResult;
    int inToday,
    inMonth,
    inDay,
    inYear,
    inMonthEnd,
    inTMonth,
    inTDay,
    inTYear,
    inLoop,
    inCnt;
    STATS srStatsHist[7];
    char szTemp[5 + 1];
    char szTemp1[10 + 1];
    char szChoice[MESSAGE_SIZE + 1];
    char szTemplateFileName[FILENAME_SIZE + 1];
    char szCurrentDateTime[CPAC_DATE_TIME_SIZE + 1];



    vdGetMessageFromFile(STATS_DAY_WEEK_MSG5x, szChoice);
    inResult = obDisp.inDO_ChooseOne(NULL, NULL, szChoice, 2, NULL_PFI);
    if (inResult == VS_ESCAPE)
        return(VS_SUCCESS);

    memset(&srStatsHist, 0, STATS_SIZE * 7);
    memset(szTemp, 0, sizeof(szTemp));
    inRollOverStats(&gsrStats);

    vdSetReportDateAndTime();
    inToday = gsrStats.chDay - 0x30;

    strcpy(szTemplateFileName, STATIC_DATA_PATH);
    strcat(szTemplateFileName, STATS_FRM1);

    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }

    if (!fGetEnablePrinter())
        return(VS_SUCCESS);

    vdDisplayMessageFromFile(PRINTING_MSG, STATUS_MSG);

    if (inSwitchTemplate(szTemplateFileName) < 0) {
        vdDisplayMessageFromFile(FORMATER_ERR_MSG, ERROR_MSG);
        return(VS_ERR);
    }


    /* -- take charge -- */
    p350ColumnMode(COLUMN_TYPE_42);

    /* -- print the header lines here 1 - 10 -- */
    vdMakeReportHeader(pobTran);
    inPrintReceiptHeader(pobTran);

    if (inPrintLines(&obPrinter, CPAC_STATS_TOP_START, CPAC_STATS_TOP_END, 0, (fGetDemoMode() ? 1L : 0L)) != VS_SUCCESS)
        return (VS_ERR);

    if (inResult == STATS_DAY_REPORT) {
        if (inCPACPrintStatsData(inToday, &gsrStats) != VS_SUCCESS)
            return(VS_ERR);
    } else {
        if (inOpenStatsHistory(&inFileDesc, srStatsHist) != VS_SUCCESS)
            return(VS_ERR);
        memset(szTemp, 0, sizeof(szTemp));
        inGetDateTime(szCurrentDateTime);
        memcpy(szTemp, szCurrentDateTime, 4);
        inYear = atoi(szTemp);
        memset(szTemp, 0, sizeof(szTemp));
        memcpy(szTemp, &szCurrentDateTime[4], 2);
        inMonth = atoi(szTemp);
        memset(szTemp, 0, sizeof(szTemp));
        memcpy(szTemp, &szCurrentDateTime[6], 2);
        inDay = atoi(szTemp);
        memset(szTemp, 0, sizeof(szTemp));
        memcpy(szTemp, &szCurrentDateTime[8], 2);

        for (inLoop = inToday, inCnt = 0; inCnt < 7; inCnt++) {
            inTDay = inDay;
            inTMonth = inMonth;
            inTYear = inYear;

            inTDay = inTDay - inCnt;
            //  inMonthEnd = month_end(inMonth, inYear);
            if (inTDay == 0) {
                if (inTMonth == 1) {
                    inTMonth = 12; inTYear--;
                    inMonthEnd = month_end(inTMonth, inTYear);
                } else {
                    inMonthEnd = month_end(inTMonth - 1, inTYear);
                    --inTMonth;
                }
                inTDay = inMonthEnd;
            } else if (inTDay < 0) {
                if (inTMonth == 1) {
                    inTMonth = 12; inTYear--;
                    inMonthEnd = month_end(inTMonth, inTYear);
                } else {
                    inMonthEnd = month_end(inTMonth - 1, inTYear);
                    --inTMonth;
                }
                inTDay = inMonthEnd + inTDay;
            }
            memset(szTemp1, 0, sizeof(szTemp1));
            sprintf(szTemp1, "%d", inTYear);
            sprintf(srRcpt.szDate, "%s%02d%02d", &szTemp1[2], inTMonth, inTDay);
            vdFormatCITIDate(srRcpt.szDate);

            if (inCPACPrintStatsData(inLoop, &srStatsHist[inLoop]) != VS_SUCCESS) {
                close(inFileDesc); //1.4 added sadiq.
                return(VS_ERR);
            }
            ((inLoop - 1 < 0) ? (inLoop = 6) : (inLoop--));
        }

        close(inFileDesc);
    }

    if (inPrintLines(&obPrinter, CPAC_STATS_EOR_START, CPAC_STATS_EOR_END, 0, 0L) != VS_SUCCESS)
        return(VS_ERR);

    vdFormFeed(&obPrinter);
    p350ColumnMode(inGetP350ColMode());

    return(VS_SUCCESS);
}

int inCPACPrintStatsData(int inDay,STATS* psrStats) {
    char* ppszDays[] = {
        "Sunday",
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday",
        "Saturday"
    };

    strcpy(gsrStatsRpt.szDay, ppszDays[inDay]);
    gsrStatsRpt.inReboots = psrStats->inRebootCount;
    gsrStatsRpt.inTransactions = psrStats->inTransCount;
    gsrStatsRpt.inCardErrs = psrStats->inCardReadErrors;
    gsrStatsRpt.inPrnErrs = psrStats->inPrinterErrors;
    gsrStatsRpt.inPinErrs = psrStats->inPinPadErrors;
    gsrStatsRpt.inNoLine = psrStats->inNoLine;
    gsrStatsRpt.inBusy = psrStats->inBusy;

    return(inPrintLines(&obPrinter, CPAC_STATS_MIDDLE_START, CPAC_STATS_MIDDLE_END, 0, 0L));
}
// #endif /* HKGM */

#ifdef CPACCLRK_C
/*********************************************************************************************
* @func int |inCPACClerkDetailReportOperation |
*
*  Initiates printing of the clerk detail report
*
*
*
* @rdesc return values.
* @flag int    |  VS_SUCCESS, VS_ERR
*
*
* @end
**********************************************************************************************/


int inCPACClerkDetailReportOperation(TRANSACTION_OBJECT* pobTran) {
    /*    pdebug(("--inClerkDetailReportOperation--"));*/

    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        vdSGErrorMessage(0L);
        return(VS_SUCCESS);
    }

    if (!fGetEnablePrinter())
        return(VS_SUCCESS);

    if (inGetClerkMode() == NO_CLERK) {
        vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
        vdSGErrorMessage(0L);
        return(VS_ERR);
    }

    if (inGetPrinterType() != NOPRINTER) {
        inGetClerkTemplate();


        inCPACPrintClerkDetailReport(pobTran, &obPrinter);

        vdSGErrorMessage(0L);
        return (VS_SUCCESS);
    }
    vdSGErrorMessage(0L);
    return(VS_SUCCESS);
}



int inCPACPrintClerkDetailReport(TRANSACTION_OBJECT* pobTran,PRINTER_OBJECT* obPrinter) {
    int inReportTop = VS_TRUE;
    int inGoodClerk;
    ADT_REC srADTRec;
    FHANDLE hADTFHandle;
    int inPrintAll = 0;
    char szClerkId[CLERK_ID_SIZE + 1];
    char szADTFileName[FILENAME_SIZE + 1] ;

    if ((inPrintAll = inGetClerkSelection(szClerkId)) == VS_ESCAPE)
        return(VS_ESCAPE);
    if (obDisp.inTitleLine == obDisp.inStatusLine || obDisp.inTitleLine == obDisp.inInputLine)
        clrscr();

    inCombineActiveClerks();
    /* This is useing temp ADT file created in CombineActiveClerks  */
    vdGetMessageFromFile(ADT_FILENAME, szADTFileName);

    /* open ADT table */
    if ((hADTFHandle = open(szADTFileName, O_RDWR)) < 0) {
        vdDisplayMessageFromFile(BATCH_EMPTY_MSG, WARNING_MSG);
        SVC_WAIT(1000);
        return(VS_ERR);
    }

    inGetClerkTemplate();

    inGoodClerk = read(hADTFHandle, (char *) &srADTRec, SIZE_ADT_REC);
    while (inGoodClerk == SIZE_ADT_REC) {
        if ((inPrintAll == KEY_ALLRPT) || ((inPrintAll == KEY_ONERPT) && (strcmp(szClerkId, srADTRec.szClerkId) == 0))) {
            /*  If record does not exist then go to next clerk  */

            strcpy(pobTran->srBKey.szClerkId, srADTRec.szClerkId);
            strcpy(srRcpt.unFrm.srDet.srMid.szClerkId, srADTRec.szClerkId);

            if ((inCPACPrintDetailCurrencyReport(pobTran, obPrinter, &inReportTop)) != VS_SUCCESS) {
                close(hADTFHandle);
                return(VS_ERR);
            }
        }

        inGoodClerk = read(hADTFHandle, (char *) &srADTRec, SIZE_ADT_REC);
    } /* end clerk loop */
    if (inReportTop == VS_FALSE) {
        if (inPrintLines(obPrinter, CPAC_CLERK_DETAIL_EOR_START, CPAC_CLERK_DETAIL_EOR_END, NO_BL_LINE, 0x80000000) != VS_SUCCESS) {
            close(hADTFHandle);
            return(VS_ERR);
        }
    }
    close(hADTFHandle);
    remove(ADT_FILE_NAME);
    return (VS_SUCCESS);
}
#endif /* CPACCLRK_C */


int inCPACPrintDetailCurrencyReport(TRANSACTION_OBJECT* pobTran,PRINTER_OBJECT* obPrinter,int* pinReportTop) {
#ifdef BATCH_DEFINED
    int inNewCurr,
    inNewClerk = VS_TRUE;
    int inResult,
    inNeedGrTot,
    inCnt = 0;
    int inNeedCurrTot,
    inCurr = 0;
    int inNumberOfRecordsinBatch;
    int inPrintDetail = VS_FALSE;
    int inStart,
    inStop,
    inMerch = 0;
    int inHostIndex;
    int inCurrencyFlag = VS_FALSE;
    int inFirstMerchant = VS_TRUE;


    /* Grand total accumulators */
    DETAIL_TOTALS srGrTot;
    /* Currency total accumulators */
    DETAIL_TOTALS srCurrTot;

    /** /pdebug(("--inPrintDetailReport--"));*/

    for (inHostIndex = 0; inHostIndex < MAX_HOSTS; inHostIndex++) {
        if (inLoadHDTRec(inHostIndex) != VS_SUCCESS) {
            //CPAC2.1B
            vdSGErrorMessage(HDT_ERR_MSG21);
            return (VS_ERR);
        }

        if (fGetAllowMultiCurrency()) {
            inCurrencyFlag = VS_TRUE;
            break;
        }
    }
    /*  Kelvin_F2 --- follow what print detail report changes and apply in here
        if ( fChkAllHostBatches(pobTran) ) */

    if (fChkHostBatches(pobTran, inGetMerchantNum() - 1)) {
        vdDisplayMessageFromFile(BATCH_EMPTY_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }

    /* determine how many merchants should be printed */
    inStart = 1;
    inStop = inGetMITTotRecs();
    vdSetMerchantNum(inGlobalMerchantHandle);

    //   for (inMerch = inStart; inMerch <= inStop; inMerch++)
    //   {
    inMerch = inGetMerchantNum();//CPAC2.1B
    if (inLoadMITRec(inMerch - 1) != VS_SUCCESS)
        return(VS_ERR);
    strlcpy(srRcpt.szMerchantName, szGetMerchantText(), sizeof(srRcpt.szMerchantName));

    inZeroDetailTotals(&srGrTot);
    inNeedGrTot = 0;  /* bb1 */

    inNumberOfRecordsinBatch = inGetDCBatchRecCnt(pobTran);
    /* Check whether the batch is empty or not */
    if (inNumberOfRecordsinBatch != 0) {
        /* Need this for inGetDCKeyBatchRec() below */
        vdBatchDCOpen(pobTran);

        if (fGetEnablePrinter())
            vdDisplayMessageFromFile(PRINTING_MSG, STATUS_MSG);

        memset(srRcpt.unFrm.srReceipt.szSChg, 0x00, sizeof(srRcpt.unFrm.srReceipt.szSChg));

        /* AS1 - only print date/time once - fix AM53390 JA127 */
        inNeedCurrTot = 0;
        for (inCurr = 0; inCurr < inGetCSTTotRecs(); inCurr++) {
            if (inLoadCSTRec(inCurr) != VS_SUCCESS) {
                vdSGErrorMessage(CST_ERR_MSG);
                return(VS_ERR);
            }
            inCnt = 0;
            inZeroDetailTotals(&srCurrTot);
            pobTran->srBKey.inCurrencyIndex = inCurr;
            strcpy(srRcpt.unFrm.srDet.srMid.szCSymbol, szGetCurSymbol());

            inNewCurr = VS_TRUE;

            srRcpt.unFrm.srDet.srMid.inTotalTipCount = 0; /* mb1 */
            srRcpt.unFrm.srDet.srMid.lnTotalTipAmt = 0;   /* mb1 */

            /* Print online records */
            if ((inResult = inGetDCKeyBatchRec(pobTran, KEY_CURRENCY + KEY_SVR_ID, &pobTran->srBKey, DB_FIRST)) == VS_SUCCESS)
                do {
                    if (inGGCode() != AUTH_ONLY  && inGGCode() != IMAM_CARDVER) {
                        if (inNewCurr) {
                            inNewCurr = VS_FALSE;
                            if (inFirstMerchant) {
                                /* Print the header */

                                if (*pinReportTop == VS_TRUE) {
                                    vdMakeReportHeader(pobTran);
                                    inPrintReceiptHeader(pobTran);
#ifdef CPACCLRK_C
                                    vdCPACSetClerkHeaderCondition(*pinReportTop, CLERK_REPORT, 1, inCurrencyFlag);
                                    inCPACPrintClerkReportHeader(pobTran, obPrinter);
#endif /* CPACCLRK_C */
                                }
                                inFirstMerchant = VS_FALSE;
                            }
                            /* Header condition should not print report title except at top of report */
#ifdef CPACCLRK_C

                            vdCPACSetClerkHeaderCondition(*pinReportTop, CLERK_REPORT, inNewClerk, inCurrencyFlag);
#endif /* CPACCLRK_C */

                            *pinReportTop = VS_FALSE;
                            inNewClerk = VS_FALSE;
#ifdef CPACCLRK_C
                            /* AS1 - print correct clerk ID */
                            if (inGetClerkMode() == NO_CLERK)
                                strcpy(srRcpt.szClerkId, " ");
                            else
                                strlcpy(srRcpt.szClerkId, pobTran->srBKey.szClerkId, CLERK_ID_SIZE);

                            if (inPrintLines(obPrinter, CPAC_CLERK_DETAIL_TOP_START, CPAC_CLERK_DETAIL_TOP_END, NO_BL_LINE, lnHeaderCondition) != VS_SUCCESS)
                                return(VS_ERR);
#endif /* CPACCLRK_C */
                        }
#ifdef CPACCLRK_C
                        if (inCPACPrtClerkDetailMiddle(obPrinter, pobTran, &srCurrTot) != VS_SUCCESS)
                            return(VS_ERR);
#endif /* CPACCLRK_C */
                        inCnt++;

                        if (act_kbd_pending_test(KEY_CANCEL))
                            return(VS_ESCAPE);
                    }
                    inResult = inGetDCKeyBatchRec(pobTran, KEY_CURRENCY + KEY_SVR_ID, &pobTran->srBKey, DB_NEXT);
                } while (inResult == VS_SUCCESS);
                /* end of key */

                /* Bottom */
            if (inCnt > 0) {
                if (inGetCSTTotRecs() > 1 && inCurrencyFlag == VS_TRUE)
                    inNeedCurrTot++;
                else
                    inNeedGrTot++;
            }
            inAccumDetailTotals(&srGrTot, &srCurrTot);
            srCurrTot.inVoidCnt = 0;

            if (inGetCSTTotRecs() > 1) {
                if ((inNeedCurrTot > 0) && (inCnt > 0)) //mb1
                {
                    /* Currency Totals */
                    inSetDetailPrintTotals(&srCurrTot);
                    vdSetDetailBottomCondition(pobTran, inPrintDetail, inNumberOfRecordsinBatch, 1, &srCurrTot);
#ifdef CPACCLRK_C
                    if (inPrintLines(obPrinter, CPAC_CLERK_DETAIL_BOTTOM_START, CPAC_CLERK_DETAIL_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
                        return(VS_ERR);
#endif /* CPACCLRK_C */
                }
            }
        }/* end currency for loop */
        inPrintDetail = VS_TRUE;

        /*  Always need grand totals if NO_SHIFT */
        if (inNeedGrTot > 0) {
            /*  Use default currency for host for grand totals */
            if (inLoadCSTRec(inGetCurrencyIdx()) != VS_SUCCESS) {
                vdSGErrorMessage(CST_ERR_MSG);
                return(VS_ERR);
            }
            /* Grand Totals */
            inSetDetailPrintTotals(&srGrTot);
            /* Param 3 indicates this is the GrandTotal bottom */
            vdSetDetailBottomCondition(pobTran, inPrintDetail, inNumberOfRecordsinBatch, 2, &srGrTot);
#ifdef CPACCLRK_C
            if (inPrintLines(obPrinter, CPAC_CLERK_DETAIL_BOTTOM_START, CPAC_CLERK_DETAIL_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
                return(VS_ERR);
#endif /* CPACCLRK_C */
        }

        memset(srRcpt.szErrorMessage, '\0', sizeof(srRcpt.szErrorMessage));
        memset(srRcpt.szStatusMessage, '\0', sizeof(srRcpt.szStatusMessage));

        vdCloseDCBatch(pobTran); /* bb1 */
    } /* end if inNumberOfRecordsinBatch != 0 */
    //    } /* merchant loop */
    return (VS_SUCCESS);
#endif
}
#ifdef CPACCLRK_C
/*-------------------------------------------------------------------------
   Function :    inCPACPrintClerkReportHeader
    Description :
    Parameters :
    Returns :
    Notes :
--------------------------------------------------------------------------*/

int inCPACPrintClerkReportHeader(TRANSACTION_OBJECT* pobTran,PRINTER_OBJECT* obPrinter) {
    /** /pdebug(("--vdMakeReportHeader--"));*/

    if (inPrintLines(obPrinter, CPAC_CLERK_DATE_START, CPAC_CLERK_DATE_END, NO_BL_LINE, lnHeaderCondition) != VS_SUCCESS)
        return(VS_ERR);

    return(VS_SUCCESS);
}

int inCPACPrtClerkDetailMiddle(PRINTER_OBJECT* obPrinter,TRANSACTION_OBJECT* pobTran,DETAIL_TOTALS* psrDetTot) {
    /* For Advice Upload requests invoice number needs to be
    picked up from the batch record - Field62 will be loaded
    from the batch record before this function is called
    */
    //Kelvin_f2 --- follow the print detail report and apply change here
    vdCPACMakeDetailMiddle(pobTran, psrDetTot);
    vdSetDetailMiddleCondition(pobTran);

    return(inPrintLines(obPrinter, CPAC_CLERK_DETAIL_MIDDLE_START, CPAC_CLERK_DETAIL_MIDDLE_END, NO_BL_LINE, lnMiddleCondition));
}

void vdCPACSetClerkHeaderCondition(int inReportTop,int inReportType,int inNewClerk,int inCurrencyFlag) {
    if (inGetPrinterType() == NOPRINTER || !fGetEnablePrinter())
        return;

    lnHeaderCondition = formater_set_flags((inReportTop && fGetDemoMode() == VS_TRUE), 0, 0, 0, (inGetApplicationType() == RESTAURANT && inNewClerk), (inGetApplicationType() == RETAIL && inNewClerk), 0, 0, (inGetMITTotRecs() > 1),
        0,
        0,
        0,

        0,
        (inGetCSTTotRecs() > 1 && inCurrencyFlag == VS_TRUE),
        0,
        0,

        (inGetTipProcessing() > TIP_OFF),
        (fGetCashBack()),
        0,
        0,

        (inGetTipProcessing() > TIP_OFF && fGetCashBack()),
        (inGetTipProcessing() > TIP_OFF && !(fGetCashBack())),
        (inGetTipProcessing() == TIP_OFF && fGetCashBack()),
        (inGetTipProcessing() == TIP_OFF && !(fGetCashBack())),

        0,
        0,
        0,
        0,

        0,
        (inReportType), /* && (inGetShiftType() == NO_SHIFT)), bb1 */
        (inReportType), /* && (inGetShiftType() != NO_SHIFT)), bb1 */
        (!inReportType), -1);
}

/*********************************************************************************************
* @func int |inCPACClerkTableReportOperation |
*
*  Initiates printing of the clerk table report
*
*
*
* @rdesc return values.
* @flag int    |  VS_SUCCESS, VS_ERR
*
*
* @end
**********************************************************************************************/


int inCPACClerkTableReportOperation(TRANSACTION_OBJECT* pobTran) {
    /*    pdebug(("--inClerkTableReportOperation--"));*/

    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }
    if (!fGetEnablePrinter())
        return(VS_SUCCESS);

    if (inGetClerkMode() != NO_CLERK) {
        inGetClerkTemplate();

        return(inCPACPrintClerkTableReport(&obPrinter, pobTran));
    }

    vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
    return(VS_ERR);
}


/*********************************************************************************************
* @func int |inCPACPrintClerkTableReport |
*
*  Initiates printing of the clerk table report
*
*
*
* @rdesc return values.
* @flag int    |  VS_SUCCESS, VS_ERR
*
*
* @end
**********************************************************************************************/


int inCPACPrintClerkTableReport(PRINTER_OBJECT* obPrinter,TRANSACTION_OBJECT* pobTran) {
    int inStart,
    inStop,
    inMerch = 0;
    UDT_REC srUDTRec;
    FHANDLE hUDTFHandle;
    int inRecordSize;

    if (fGetEnablePrinter())
        vdDisplayMessageFromFile(PRINTING_MSG, STATUS_MSG);

    inStart = 1;
    inStop = inGetMITTotRecs();

    vdSetMerchantNum(inGlobalMerchantHandle);
    inMerch = inGetMerchantNum();
    if (inLoadMITRec(inMerch - 1) != VS_SUCCESS)
        return(VS_ERR);

    vdMakeReportHeader(pobTran);
    inPrintReceiptHeader(pobTran);

    vdSetClerkTableHeaderCondition();

    if (inPrintLines(obPrinter, CPAC_CLERK_TABLE_TOP_START, CPAC_CLERK_TABLE_TOP_END, NO_BL_LINE, lnHeaderCondition) != VS_SUCCESS)
        return(VS_ERR);

    if ((hUDTFHandle = open(UDT_FILENAME, O_RDWR)) < 0)
        return(VS_ERR);

    if (lseek(hUDTFHandle, (long) GEN_VER_SIZE, SEEK_SET) != (long) GEN_VER_SIZE) {
        close(hUDTFHandle);
        return(VS_ERR);
    }

    vdSetClerkTableMiddleCondition();
    do {
        if ((inRecordSize = read(hUDTFHandle, (char *) &srUDTRec, SIZE_UDT_REC)) == SIZE_UDT_REC) {
            strcpy(srRcpt.szClerkId, srUDTRec.szClerkId);
            strcpy(srRcpt.szInvNum, srUDTRec.szClerkPasswd);

            if (inGetClerkMode() == CLERK_LGN) {
                if (srUDTRec.inLogedIn)
                    strcpy(srRcpt.unFrm.srReceipt.szCType, "Yes");
                else
                    strcpy(srRcpt.unFrm.srReceipt.szCType, "No");
            }
            if (inPrintLines(obPrinter, CPAC_CLERK_TABLE_MIDDLE_START, CPAC_CLERK_TABLE_MIDDLE_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS) {
                close(hUDTFHandle);
                return(VS_ERR);
            }
            if (act_kbd_pending_test(KEY_CANCEL)) {
                close(hUDTFHandle);
                return(VS_ESCAPE);
            }
        }
    } while (inRecordSize == SIZE_UDT_REC);

    close(hUDTFHandle);

    if (inPrintLines(obPrinter, CPAC_CLERK_TABLE_BOTTOM_START, CPAC_CLERK_TABLE_BOTTOM_END, NO_BL_LINE, 0L) != VS_SUCCESS)
        return(VS_ERR);

    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func int |inCPACClerkTotalsReportOperation |
*
*  Initiates printing of the clerk totals report
*
*
*
* @rdesc return values.
* @flag int    |  VS_SUCCESS, VS_ERR
*
*
* @end
**********************************************************************************************/


int inCPACClerkTotalsReportOperation(TRANSACTION_OBJECT* pobTran) {
    /*    pdebug(("--inClerkTotalsReportOperation--"));*/

    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }
    if (!fGetEnablePrinter())
        return(VS_SUCCESS);
    if (inGetClerkMode() != NO_CLERK) {
        inGetClerkTemplate();

        return(inCPACPrintClerkTotalsReport(pobTran, &obPrinter));
    }

    vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
    return(VS_ERR);
}

/*********************************************************************************************
* @func int |inCPACPrintClerkTotalsReport |
*
*  Browes through the batch and prints the total report.

*
*
*
* @rdesc return values.
* @flag int    |  VS_SUCCESS, VS_ERR
*
*
* @end
**********************************************************************************************/


int inCPACPrintClerkTotalsReport(TRANSACTION_OBJECT* pobTran,PRINTER_OBJECT* obPrinter) {
    int inStart,
    inStop,
    inMerch = 0;
    int inHostIndex;
    int inGoodClerk;
    ADT_REC srADTRec;
    FHANDLE hADTFHandle;
    char szADTFileName[FILENAME_SIZE + 1];
    UTT_REC srUTTRec;
    UTT_KEY srUTTKey;
    char szUTTFileName[FILENAME_SIZE + 1] ;
    DB_FILE srDBFPtr;
    int inRetVal;
    int inReportTop = VS_TRUE;
    CLERK_TOTS_REC srGrandTots;
    CLERK_TOTS_REC srClerkTots;

    memset((char *) &srGrandTots, 0x00, (SIZE_CLERK_TOTS_REC));

    if (fGetEnablePrinter())
        vdDisplayMessageFromFile(PRINTING_MSG, STATUS_MSG);

    if (inLoadMITRec(0) != VS_SUCCESS)
        return(VS_ERR);
    inCombineActiveClerks();
    /* This is useing temp ADT file created in CombineActiveClerks  */
    vdGetMessageFromFile(ADT_FILENAME, szADTFileName);

    /* open ADT table */
    if ((hADTFHandle = open(szADTFileName, O_RDWR)) < 0) {
        vdDisplayMessageFromFile(BATCH_EMPTY_MSG, WARNING_MSG);
        SVC_WAIT(1000);
        return(VS_ERR);
    }

    inStart = 1;
    inStop = inGetMITTotRecs();


    inGoodClerk = read(hADTFHandle, (char *) &srADTRec, SIZE_ADT_REC);

    while (inGoodClerk == SIZE_ADT_REC) {
        memset((char *) &srClerkTots, 0x00, SIZE_CLERK_TOTS_REC);
        strcpy(pobTran->srBKey.szClerkId, srADTRec.szClerkId);
        //       for (inMerch = inStart; inMerch <= inStop; inMerch++)
        //       {
        //Kelvin_F2 --- follow print detail report and apply here
        vdSetMerchantNum(inGlobalMerchantHandle);

        inMerch = inGetMerchantNum();
        if (inLoadMITRec(inMerch - 1) != VS_SUCCESS)
            return(VS_ERR);

        /* open correct merchant batch */
        if (inGetDCBatchRecCnt(pobTran) == 0) {
            //continue;
            break;
        }

        for (inHostIndex = 0; inHostIndex < MAX_HOSTS; inHostIndex++) {
            //              vdSetHostHandle(inHostIndex);

            if (inLoadDefaultHost(inHostIndex) != VS_SUCCESS)
                return (VS_ERR);

            if (inLoadDefaultCurrency(pobTran) != VS_SUCCESS)
                return (VS_ERR);

            /* Only print the report for independent host */
            if (!fIsIndependentBatch(inHostIndex))
                continue;
            vdGetUTTFileName(szUTTFileName);

            if (inOpenUTT(&srDBFPtr, szUTTFileName) < 0)
                return(VS_ERR);

            strcpy(srUTTKey.szClerkID, srADTRec.szClerkId);
            inRetVal = inGetKeyUTTRec(&srDBFPtr, &srUTTRec, &srUTTKey, KEY_SVR_ID, DB_FIRST);

            if (inRetVal != VS_ERROR)
                do {
                    /* Bottom totals */
                    srClerkTots.inCount += srUTTRec.inNetCount;
                    srClerkTots.lnTotAmt += srUTTRec.lnNetTotAmt;
                    srClerkTots.lnBaseAmt += srUTTRec.lnNetBaseAmt;
                    srClerkTots.lnTaxAmt += srUTTRec.lnNetTaxAmt;
                    srClerkTots.lnTipAmt += srUTTRec.lnNetTipAmt;
                    srClerkTots.lnCashBack += srUTTRec.lnNetCashBack;
                    srClerkTots.lnSurcharge += srUTTRec.lnNetSurcharge;
                    srClerkTots.lnTipSale += srUTTRec.lnTipSale;

                    srGrandTots.inCount += srUTTRec.inNetCount;
                    srGrandTots.lnTotAmt += srUTTRec.lnNetTotAmt;
                    srGrandTots.lnBaseAmt += srUTTRec.lnNetBaseAmt;
                    srGrandTots.lnTaxAmt += srUTTRec.lnNetTaxAmt;
                    srGrandTots.lnTipAmt += srUTTRec.lnNetTipAmt;
                    srGrandTots.lnCashBack += srUTTRec.lnNetCashBack;
                    srGrandTots.lnSurcharge += srUTTRec.lnNetSurcharge;
                    srGrandTots.lnTipSale += srUTTRec.lnTipSale;

                    strcpy(srUTTKey.szClerkID, srADTRec.szClerkId);
                    inRetVal = inGetKeyUTTRec(&srDBFPtr, &srUTTRec, &srUTTKey, KEY_SVR_ID, DB_NEXT);
                } while (inRetVal != VS_ERR);  /* end if */
            inCloseUTT(&srDBFPtr);
        } /* end of host loop */
        //        } /* end of Merch loop */
        if (inReportTop == VS_TRUE) {
            vdMakeReportHeader(pobTran);
            inPrintReptHeader(pobTran, obPrinter);

            vdSetClerkTotalHeaderCondition(inReportTop, VS_FALSE);
            inReportTop = VS_FALSE;
            if (inPrintLines(obPrinter, CPAC_CLERK_TOTAL_TOP_START, CPAC_CLERK_TOTAL_TOP_END, NO_BL_LINE, lnHeaderCondition) != VS_SUCCESS)
                return(VS_ERR);
        }
        inPrintClerkTotalsRecord(obPrinter, &srClerkTots, 0, srADTRec.szClerkId);
        inGoodClerk = read(hADTFHandle, (char *) &srADTRec, SIZE_ADT_REC);
    } /* end clerk loop */

    close(hADTFHandle); /* through with ADT temp file*/
    remove(ADT_FILE_NAME);

    /* Check whether the batch is empty or not */
    if (inReportTop == VS_TRUE) {
        vdDisplayMessageFromFile(BATCH_EMPTY_MSG, WARNING_MSG);
        SVC_WAIT(1000);
        return(VS_ERR);
    } else
        inCPACPrintClerkTotalsBottom(pobTran, obPrinter, &srGrandTots, VS_TRUE);

    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func int |inCPACPrintClerkTotalsBottom |
*
*  Initiates printing of clerk totals report bottom section
*
*
*
* @rdesc return values.
* @flag int    |  VS_SUCCESS, VS_ERR
*
*
* @end
**********************************************************************************************/

int inCPACPrintClerkTotalsBottom(TRANSACTION_OBJECT* pobTran,PRINTER_OBJECT* obPrinter,CLERK_TOTS_REC* psrGrandTots,int inFormFeed) {
    sprintf(srRcpt.unFrm.srSubTotal.srTerm.szCreditTotal, SUBSTITUTE_LD, psrGrandTots->lnBaseAmt);
    sprintf(srRcpt.unFrm.srSubTotal.srTerm.szTipTotal, SUBSTITUTE_LD, psrGrandTots->lnTipAmt);
    sprintf(srRcpt.unFrm.srSubTotal.srTerm.szCashBack, SUBSTITUTE_LD, psrGrandTots->lnCashBack);
    sprintf(srRcpt.unFrm.srSubTotal.srTerm.szTotalSchgAmt, SUBSTITUTE_LD, psrGrandTots->lnSurcharge);
    sprintf(srRcpt.unFrm.srSubTotal.srTerm.szNetTotal, SUBSTITUTE_LD, psrGrandTots->lnTotAmt);
    sprintf(srRcpt.unFrm.srSubTotal.srTerm.szTaxTotal, SUBSTITUTE_LD, psrGrandTots->lnTaxAmt);

    vdFormatAmount(srRcpt.unFrm.srSubTotal.srTerm.szCreditTotal, VS_TRUE);
    vdFormatAmount(srRcpt.unFrm.srSubTotal.srTerm.szTipTotal, VS_TRUE);
    vdFormatAmount(srRcpt.unFrm.srSubTotal.srTerm.szCashBack, VS_TRUE);
    vdFormatAmount(srRcpt.unFrm.srSubTotal.srTerm.szTotalSchgAmt, VS_TRUE);
    vdFormatAmount(srRcpt.unFrm.srSubTotal.srTerm.szNetTotal, VS_TRUE);
    vdFormatAmount(srRcpt.unFrm.srSubTotal.srTerm.szTaxTotal, VS_TRUE);

    vdSetClerkTotalBottomCondition(pobTran, inFormFeed, psrGrandTots->lnSurcharge, psrGrandTots->lnTaxAmt);
    if (inPrintLines(obPrinter, CPAC_CLERK_TOTAL_BOTTOM_START, CPAC_CLERK_TOTAL_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
        return(VS_ERR);

    if (inPrintLines(obPrinter, CPAC_CLERK_TOTAL_EOR_START, CPAC_CLERK_TOTAL_EOR_END, 0, 0L) != VS_SUCCESS)
        return(VS_ERR);

    return(VS_SUCCESS);
}
#endif /* CPACCLRK_C */

#ifdef HKGM
/*********************************************************************************************
* @func int | inHKGMReprintAnyReceiptOperation |
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

int inHKGMReprintAnyReceiptOperation(TRANSACTION_OBJECT* pobTran) {
    /** /pdebug(("--inReprintAnyReceiptOperation--"));*/

    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }

    if (!fGetEnablePrinter())
        return(VS_SUCCESS);

    return(inHKGMReprintRecpt(pobTran->srBKey.lnInvNum, &obPrinter, pobTran));
}

/*********************************************************************************************
* @func int | inHKGMReprintLastReceiptOperation |
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/
#define     HKGM_REPRINT_LAST_INVOICE       -99L

int inHKGMReprintLastReceiptOperation(TRANSACTION_OBJECT* pobTran) {
    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }

    if (!fGetEnablePrinter())
        return(VS_SUCCESS);

    vdSetPrintReceipt(pobTran, VS_TRUE);
    return (inHKGMReprintRecpt(HKGM_REPRINT_LAST_INVOICE, &obPrinter, pobTran));
}

/*********************************************************************************************
* @func static int | inHKGMReprintRecpt |
*
*       This function is changed to be used to re-print LAST
*       receipt also, in addition to re-print the transactions in
*       the batch. If the invoice number is ZERO, it is considered
*       as "Reprint last receipt".
*
* @parm long    | lnInvNum  |
* @parm PRINTER_OBJECT *    | obPrinter |
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

static int inHKGMReprintRecpt(long lnInvNum,PRINTER_OBJECT* obPrinter,TRANSACTION_OBJECT* pobTran) {
    int inResult;
    DB_FILE dbReprintFile;


    pdebug(("--inReprintRecpt--"));

    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }

    if (!fGetEnablePrinter())
        return(VS_SUCCESS);

    pobTran->srBKey.lnInvNum = lnInvNum;

    if (lnInvNum == HKGM_REPRINT_LAST_INVOICE)             /* Reprint LAST receipt */ {
        /** /pdebug(("Reprint last receipt"));*/


        if (inOpenBatch(&dbReprintFile, REPRINT_FILE_NAME) != VS_SUCCESS) {

            vdSGErrorMessage(BATCH_ERR_MSG);
            return(VS_ERR);
        }
        if (inReadReprintBatchData(&dbReprintFile, &pobTran->srBKey, &pobTran->srBRec, 0L) != VS_SUCCESS) {
            vdSGErrorMessage(NO_DATA_MSG);
            inCloseBatch(&dbReprintFile); //Bug fix for SQA_B by kelvin_f2
            return(VS_ERR);
        }

        if (inCloseBatch(&dbReprintFile) != VS_SUCCESS) {

            vdSGErrorMessage(BATCH_ERR_MSG);
            return(VS_ERR);
        }

        inLoadMITRec(pobTran->srBRec.inMerchantIndex);

        inLoadCardCurrenyHostData(pobTran);

        /* In CoreFix, if you remove the call to inLoadDefaultCurrency(), */
        /* which reloads the CST with the HDT currency index, in */
        /* inLoadCDTandCST() then the patch below is not needed.   */
        /* 08/08/00 - mdm */

        /* The CoreFix wasn't quite made, the original inLoadCDTandCST() */
        /* function was just renamed inLoadCardCurrenyHostData() so this */
        /* patch is still needed for now - 08/22/00 */

        /* Load the correct currency for this record, multi-currency error */
        if (inLoadCSTRec(pobTran->srBKey.inCurrencyIndex) != VS_SUCCESS) {
            vdDisplayMessageFromFile(CST_ERR_MSG, WARNING_MSG);
            return(VS_ERR);
        }
    } else {
        pdebug(("Reprint any receipt"));

        /*
         *      Search Data Capture batch first, then Open Tab batch.
         */
        if (inGetDCInvBatchRec(pobTran, KEY_ALL_RECS, DB_FIRST) != VS_SUCCESS) {
            vdBatchOTOpen(pobTran);
            inResult = inGetOTInvBatchRec(pobTran, KEY_ALL_RECS, DB_FIRST);
            vdCloseTabBatch(pobTran);
            if (inResult != VS_SUCCESS) {
                /**/pdebug(("Not in Tab Batch Either"));/**/
                vdDisplayErrorMessage(NO_MATCH_MSG21);
                return(VS_ERR);
            }
        } /* end if not found in DC batch */


        /* In CoreFix, if you remove the call to inLoadDefaultCurrency(), */
        /* which reloads the CST with the HDT currency index, in */
        /* inLoadCDTandCST() then the patch below is not needed.   */
        /* inLoadCDTandCST() is called by inGetDCInvBatchRec() and */
        /* inGetOTInvBatchRec() above.  08/08/00 - mdm */

        /* The CoreFix wasn't quite made, the original inLoadCDTandCST() */
        /* function was just renamed inLoadCardCurrenyHostData() so this */
        /* patch is still needed for now - 08/22/00 */

        /* Load the correct currency for this record, multi-currency error */
        if (inLoadCSTRec(pobTran->srBKey.inCurrencyIndex) != VS_SUCCESS) {
            vdDisplayMessageFromFile(CST_ERR_MSG, WARNING_MSG);
            return(VS_ERR);
        }
    } /* end else reprint any receipt */

    inGetReceiptTemplate(pobTran);
    if (inChkPrinterStatus(obPrinter) != VS_SUCCESS)
        return(VS_ERR);

    //Bug fix for SQA_B by kelvin_f2
    //inHKGMGetReceiptCopy(pobTran);
    if (inHKGMGetReceiptCopy(pobTran) != VS_SUCCESS)
        return(VS_ERR);

    vdMakeFooter(pobTran);
    vdBuildReceipt(pobTran);


    if (inResult = inRunFormSegments(pobTran, REPRINT_RECEIPT) != VS_SUCCESS)
        return(VS_ERR);

    return(VS_SUCCESS);
}

int inHKGMGetReceiptCopy(TRANSACTION_OBJECT* pobTran) {
    int inRetVal = VS_FALSE;
    signed char chAnswer;

    int inGrid,
    inFontType;
    char szChiMsgBuffer[DISP_STR_LEN + 1];

    inGrid = getgrid();
    inFontType = get_font_mode();

    if (inGrid == 0)  //16 0r 8 chars
    {
        //Chinese version
        memset(szChiMsgBuffer, NULL_CH, sizeof(szChiMsgBuffer));
        vdGetMessageFromFile(REPRINT_WHICH_COPY, szChiMsgBuffer);

        vdClearNonTitleLines();
        vdDisplayAt(1, 3, szChiMsgBuffer, NO_CLEAR);

        chAnswer = (char) obDisp.inDO_ChooseOne(NULL, NULL, pchGetMsg(REP_RCPT_COPY_OPTION_MSG), 4, NULL_PFI);
    } else {
        //English version
        chAnswer = (char) obDisp.inDO_ChooseOne(NULL, pchGetMsg(REPRINT_WHICH_COPY), pchGetMsg(REP_RCPT_COPY_OPTION_MSG), 4, NULL_PFI);
    }

    if (chAnswer == VS_ESCAPE)
        inRetVal = VS_ABORT;
    else
        switch (chAnswer) {
        case 1:
            /* Clerk */
            pobTran->srBRec.inPrintOption = PRT_MERCH | PRT_DUPLICATE;
            inRetVal = VS_SUCCESS;
            break;
        case 2:
            pobTran->srBRec.inPrintOption = PRT_CUST | PRT_DUPLICATE;
            inRetVal = VS_SUCCESS;
            break;
        case 3:
            pobTran->srBRec.inPrintOption = PRT_BANK | PRT_DUPLICATE;
            inRetVal = VS_SUCCESS;
            break;
        case 4:
            inRetVal = VS_ABORT;
            break;
        }

    return(inRetVal);
}
#endif /* HKGM */

int inCPACReprintLastReceiptOperation(TRANSACTION_OBJECT* pobTran) {
    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }

    if (!fGetEnablePrinter())
        return(VS_SUCCESS);

    vdSetPrintReceipt(pobTran, VS_TRUE);
    return (inCPACReprintRecpt((long) CPAC_REPRINT_LAST_INVOICE, &obPrinter, pobTran, 0));

    //vdSGErrorMessage(0L);
}



int inCPACReprintRecpt(long lnInvNum,PRINTER_OBJECT* obPrinter,TRANSACTION_OBJECT* pobTran,int inChoice) {
    int inResult;
    DB_FILE dbReprintFile;


    pdebug(("--inReprintRecpt--"));



    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }

    if (!fGetEnablePrinter())
        return(VS_SUCCESS);

    pobTran->srBKey.lnInvNum = lnInvNum;

    if (lnInvNum == CPAC_REPRINT_LAST_INVOICE)             /* Reprint LAST receipt */ {
        /** /pdebug(("Reprint last receipt"));*/


        if (inOpenBatch(&dbReprintFile, REPRINT_FILE_NAME) != VS_SUCCESS) {

            vdSGErrorMessage(BATCH_ERR_MSG);
            return(VS_ERR);
        }
        if (inReadReprintBatchData(&dbReprintFile, &pobTran->srBKey, &pobTran->srBRec, 0L) != VS_SUCCESS) {
            vdSGErrorMessage(NO_DATA_MSG);
            inCloseBatch(&dbReprintFile);
            return(VS_ERR);
        }

        if (inCloseBatch(&dbReprintFile) != VS_SUCCESS) {

            vdSGErrorMessage(BATCH_ERR_MSG);
            return(VS_ERR);
        }

        inLoadMITRec(pobTran->srBRec.inMerchantIndex);

        inLoadCardCurrenyHostData(pobTran);

        /* In CoreFix, if you remove the call to inLoadDefaultCurrency(), */
        /* which reloads the CST with the HDT currency index, in */
        /* inLoadCDTandCST() then the patch below is not needed.   */
        /* 08/08/00 - mdm */

        /* The CoreFix wasn't quite made, the original inLoadCDTandCST() */
        /* function was just renamed inLoadCardCurrenyHostData() so this */
        /* patch is still needed for now - 08/22/00 */

        /* Load the correct currency for this record, multi-currency error */
        if (inLoadCSTRec(pobTran->srBKey.inCurrencyIndex) != VS_SUCCESS) {
            vdDisplayMessageFromFile(CST_ERR_MSG, WARNING_MSG);
            return(VS_ERR);
        }
    } else {
        pdebug(("Reprint any receipt"));

        /*
         *      Search Data Capture batch first, then Open Tab batch.
         */
        if (inGetDCInvBatchRec(pobTran, KEY_ALL_RECS, DB_FIRST) != VS_SUCCESS) {
            vdBatchOTOpen(pobTran);
            inResult = inGetOTInvBatchRec(pobTran, KEY_ALL_RECS, DB_FIRST);
            vdCloseTabBatch(pobTran);
            if (inResult != VS_SUCCESS) {
                /**/pdebug(("Not in Tab Batch Either"));/**/
                vdDisplayErrorMessage(CPAC_NO_MATCH_MSG);
                return(VS_ERR);
            }
        } /* end if not found in DC batch */


        /* In CoreFix, if you remove the call to inLoadDefaultCurrency(), */
        /* which reloads the CST with the HDT currency index, in */
        /* inLoadCDTandCST() then the patch below is not needed.   */
        /* inLoadCDTandCST() is called by inGetDCInvBatchRec() and */
        /* inGetOTInvBatchRec() above.  08/08/00 - mdm */

        /* The CoreFix wasn't quite made, the original inLoadCDTandCST() */
        /* function was just renamed inLoadCardCurrenyHostData() so this */
        /* patch is still needed for now - 08/22/00 */

        /* Load the correct currency for this record, multi-currency error */
        if (inLoadCSTRec(pobTran->srBKey.inCurrencyIndex) != VS_SUCCESS) {
            vdDisplayMessageFromFile(CST_ERR_MSG, WARNING_MSG);
            return(VS_ERR);
        }
    } /* end else reprint any receipt */

#ifdef ICICI
 if(strcmp(szGetHostFileName(),"AXAP")!=0) //Changed from szGetHostName....Renu
	{
    if (inGetHostTranCnt(pobTran) < 1) {
        vdDisplayMessageFromFile(BATCH_EMPTY_MSG, WARNING_MSG);
        //  return(BATCH_EMPTY_MSG);
        vdSGErrorMessage(0L);
        return (VS_ERROR);
    }
 	}
 #endif  /*  ICICI  */

    inGetReceiptTemplate(pobTran);
    if (inChkPrinterStatus(obPrinter) != VS_SUCCESS)
        return(VS_ERR);

    vdMakeFooter(pobTran);
    vdBuildReceipt(pobTran);

    /*   if(inChoice == 1)
       {
            inResult = inRunFormSegments(pobTran, REPRINT_RECEIPT);
            if(inResult != VS_SUCCESS)
                return(VS_ERROR);
       }
       else*/ {
        if (inCPACGetReceiptCopy(pobTran, inChoice) != VS_SUCCESS)
            return (VS_ERR);
    }
    return(VS_SUCCESS);
}


int inCPACGetReceiptCopy(TRANSACTION_OBJECT* pobTran,int inChoice) {
    int inResult = VS_FALSE;

    /*if(inChoice == 1)
    {
        pobTran->srBRec.inPrintOption = inCpChoice;
        inResult = inRunFormSegments(pobTran, REPRINT_RECEIPT);

    }
    else*/ {
        pobTran->srBRec.inPrintOption = PRT_MERCH | PRT_DUPLICATE;

        strcpy(srRcpt.unFrm.srReceipt.szCHolder, pobTran->srBRec.szCHolder);

        inResult = inRunFormSegments(pobTran, REPRINT_RECEIPT);

        if (fCustomerReceipt(pobTran)) {
            pobTran->srBRec.inPrintOption = PRT_CUST | PRT_DUPLICATE;
            inResult = inRunFormSegments(pobTran, REPRINT_RECEIPT);
        }
#if REPRNT_BANK_CPY
        if (fCITICustomerReceipt(pobTran)) {
            pobTran->srBRec.inPrintOption = PRT_BANK | PRT_DUPLICATE;
            inResult = inRunFormSegments(pobTran, REPRINT_RECEIPT);
        }
#endif /* REPRNT_BANK_CPY */
    }

    return(inResult);
}



/*-------------------------------------------------------------------------
    Function :  vdCPACGetMessageFromReceiptFile()
    Description :
    Parameters :
    Returns :
    Globals :
    Notes :
    Modification History :
      #     Date      Who                     Description
    ----- -------- ---------- ---------------------------------------------
      1    9/15/98 Page_K1    Call inGetReceiptLCT().
--------------------------------------------------------------------------*/
void vdCPACGetMessageFromReceiptFile(long lnMessageIndex,char* szMessageBuffer,TRANSACTION_OBJECT* pobTran) {
    int inMsgTblIndex;
    int inMessageIndex;
    char szFileNameBuffer[MSG_FILE_NAME_SIZE];

    inMsgTblIndex = (int) (lnMessageIndex >> 16);
    inMessageIndex = (int) (lnMessageIndex & 0x0000ffff);

    if ((getgrid() == 0) && (get_font_mode() == 2)) // 2 byte addressing scheme + 16x16 Font
        inLoadLCTRec(0);
    //  else
    //      inGetReceiptLCT(pobTran);

    memset(szFileNameBuffer, 0, MSG_FILE_NAME_SIZE);
    inGetMessageFileName(inMsgTblIndex, szFileNameBuffer);

    if (inMsgTblIndex > 0) {
        if (inSelectMessageFile(szFileNameBuffer) != VS_SUCCESS) {
            if ((getgrid() == 0) && (get_font_mode() == 2)) // 2 byte addressing scheme + 16x16 Font
                inGetDefaultLCT();  /// bring back the old LCT
            return;
        }
    }

    if (msg_get(abs(inMessageIndex), szMessageBuffer) == NULL) {
        if ((getgrid() == 0) && (get_font_mode() == 2)) // 2 byte addressing scheme + 16x16 Font
            inGetDefaultLCT();  /// bring back the old LCT
        return;
    }

    if ((getgrid() == 0) && (get_font_mode() == 2)) // 2 byte addressing scheme + 16x16 Font
        inGetDefaultLCT();  /// bring back the old LCT
}


/*   Saritha_b1............Start...............Reprint Settlement Report */

/*   This function Reprints the Settlement Report exactly like Settlement based on Card types */

// #ifdef TLFB  (Made this feature as the part of CPAC Base Application)
int inCPACRePrintSettleReport(PRINTER_OBJECT* pobPrinter,TRANSACTION_OBJECT* pobTran) {
    char szFileName[FILENAME_SIZE + 1];
    int inNoOfRecs,
    inRecCnt = 1,
    Count,
    inNoBytes;
    int Grand = 0;
    long lnHeaderCond,
    lnMiddleCond,
    lnBottomCond;

    /*  Printing Settlement Header */


    vdGetReprintSettleFileName(szFileName, CPAC_HEADER);

    if (inDBFileExists(szFileName) != VS_SUCCESS) {
        vdDisplayErrorMessage(REC_NOT_FOUND_ERR_MSG);
        return(VS_ERR);
    }

    inPrintReceiptHeader(pobTran);


    inNoBytes = inDBReadRecord(szFileName, 1, (unsigned char *) &srCPACSettleHeader);
    if (inNoBytes < 0)
        return (VS_ERR);

    strcpy(srRcpt.szDate, srCPACSettleHeader.szDate);
    strcpy(srRcpt.szTime, srCPACSettleHeader.szTime);
	#if 0  // imam 
	   	  inSetCPACMaskTIDMID(pobTran,srRcpt.szTermId,srRcpt.szMerchantId);
		      strcpy(srCPACSettleHeader.szMID, srRcpt.szMerchantId);
                    strcpy(srCPACSettleHeader.szTID, srRcpt.szTermId);
	//	#else
                    strcpy(srCPACSettleHeader.szMID, srRcpt.szMerchantId);
                    strcpy(srCPACSettleHeader.szTID, srRcpt.szTermId);
		#endif	
		
    strcpy(srRcpt.szMerchantId, srCPACSettleHeader.szMID);
    strcpy(srRcpt.szTermId, srCPACSettleHeader.szTID);
    strcpy(srRcpt.szBatchNum, srCPACSettleHeader.szBatchNum);
    strcpy(srRcpt.szHostName, srCPACSettleHeader.szHostName);
    lnHeaderCond = srCPACSettleHeader.lnHeaderCond;
    lnHeaderCond |= 0x10000000L; //Kelvin_f2 make it print "DUPLICATE" line

#ifdef AMEX_SOC
    strcpy(srRcpt.unFrm.srReceipt.szGenBuf2, srCPACSettleHeader.szSOC);
#endif   /*  AMEX_SOC */

    if (inPrintLines(pobPrinter, CPAC_SUMMARY_TOP_START, CPAC_SUMMARY_TOP_END, NO_BL_LINE, lnHeaderCond) != VS_SUCCESS)
        return(VS_ERR);

#ifdef AMEX_SOC
    if (strcmp(szGetHostFileName(), "AXAP") == 0) {
        if (inPrintLines(&obPrinter, AMEX_SOC_PRINT_START, AMEX_SOC_PRINT_END, NO_BL_LINE, 4L) != VS_SUCCESS)
            return(VS_ERR);
    } else {
        // If it is not AXAP, depend on condition line set in TPL file.
        if (inPrintLines(&obPrinter, AMEX_SOC_PRINT_START, AMEX_SOC_PRINT_END, NO_BL_LINE, 2L) != VS_SUCCESS)
            return(VS_ERR);
    }

#endif /*   AMEX_SOC */


    /* Printing the Body of the Settlement Report */

    vdGetReprintSettleFileName(szFileName, CPAC_BODY);

    if (inDBFileExists(szFileName) != VS_SUCCESS) {
        vdDisplayErrorMessage(REC_NOT_FOUND_ERR_MSG);
        return(VS_ERR);
    }

    inNoOfRecs = inDBTotalRecords(szFileName);

    if (inNoOfRecs == 1) {
        inNoBytes = inDBReadRecord(szFileName, inNoOfRecs, (unsigned char *) &srCPACSettleMiddle);
        if (inNoBytes < 0)
            return (VS_ERR);

        strcpy(srRcpt.unFrm.srSummary.srMid.szCType, srCPACSettleMiddle.szCardName);
        strcpy(srRcpt.unFrm.srSummary.srMid.szCreditCount, srCPACSettleMiddle.szCreditCnt);
        strcpy(srRcpt.unFrm.srSummary.srMid.szCreditTotal, srCPACSettleMiddle.szCreditTot);
        strcpy(srRcpt.unFrm.srSummary.srMid.szDebitCount, srCPACSettleMiddle.szDebitCnt);
        strcpy(srRcpt.unFrm.srSummary.srMid.szDebitTotal, srCPACSettleMiddle.szDebitTot);
        strcpy(srRcpt.unFrm.srSummary.srMid.szShiftNumber, srCPACSettleMiddle.szShiftNum);
        strcpy(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, srCPACSettleMiddle.szSurCharge);
        strcpy(srRcpt.unFrm.srSummary.srMid.szAdjustCount, srCPACSettleMiddle.szAdjCnt);
        strcpy(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, srCPACSettleMiddle.szAdjTot);
        strcpy(srRcpt.unFrm.srSummary.srMid.szReversalCount, srCPACSettleMiddle.szReversalCnt);
        strcpy(srRcpt.unFrm.srSummary.srMid.szReversalTotal, srCPACSettleMiddle.szReversalTot);
        strcpy(srRcpt.unFrm.srSummary.srMid.szNetCount, srCPACSettleMiddle.szNetCnt);
        strcpy(srRcpt.unFrm.srSummary.srMid.szNetTotal, srCPACSettleMiddle.szNetTot);
        lnMiddleCond = srCPACSettleMiddle.lnMiddleCond;

        if (inPrintLines(pobPrinter, CPAC_SUMMARY_MIDDLE_START, CPAC_SUMMARY_MIDDLE_END, NO_BL_LINE, lnMiddleCond) != VS_SUCCESS)
            return(VS_ERR);
    } else {
        for (Count = 1; Count < inNoOfRecs; Count++) {
            inNoBytes = inDBReadRecord(szFileName, Count, (unsigned char *) &srCPACSettleMiddle);
            if (inNoBytes < 0)
                return (VS_ERR);

            strcpy(srRcpt.unFrm.srSummary.srMid.szCType, srCPACSettleMiddle.szCardName);
            strcpy(srRcpt.unFrm.srSummary.srMid.szCreditCount, srCPACSettleMiddle.szCreditCnt);
            strcpy(srRcpt.unFrm.srSummary.srMid.szCreditTotal, srCPACSettleMiddle.szCreditTot);
            strcpy(srRcpt.unFrm.srSummary.srMid.szDebitCount, srCPACSettleMiddle.szDebitCnt);
            strcpy(srRcpt.unFrm.srSummary.srMid.szDebitTotal, srCPACSettleMiddle.szDebitTot);
            strcpy(srRcpt.unFrm.srSummary.srMid.szShiftNumber, srCPACSettleMiddle.szShiftNum);
            strcpy(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, srCPACSettleMiddle.szSurCharge);
            strcpy(srRcpt.unFrm.srSummary.srMid.szAdjustCount, srCPACSettleMiddle.szAdjCnt);
            strcpy(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, srCPACSettleMiddle.szAdjTot);
            strcpy(srRcpt.unFrm.srSummary.srMid.szReversalCount, srCPACSettleMiddle.szReversalCnt);
            strcpy(srRcpt.unFrm.srSummary.srMid.szReversalTotal, srCPACSettleMiddle.szReversalTot);
            strcpy(srRcpt.unFrm.srSummary.srMid.szNetCount, srCPACSettleMiddle.szNetCnt);
            strcpy(srRcpt.unFrm.srSummary.srMid.szNetTotal, srCPACSettleMiddle.szNetTot);
            lnMiddleCond = srCPACSettleMiddle.lnMiddleCond;

            if (inPrintLines(pobPrinter, CPAC_SUMMARY_MIDDLE_START, CPAC_SUMMARY_MIDDLE_END, NO_BL_LINE, lnMiddleCond) != VS_SUCCESS)
                return(VS_ERR);
        }

        /* Printing Grand Totals if any */

        inNoBytes = inDBReadRecord(szFileName, Count, (unsigned char *) &srCPACSettleMiddle);
        if (inNoBytes < 0)
            return (VS_ERR);

        strcpy(srRcpt.unFrm.srSummary.srMid.szCType, srCPACSettleMiddle.szCardName);
        strcpy(srRcpt.unFrm.srSummary.srMid.szCreditCount, srCPACSettleMiddle.szCreditCnt);
        strcpy(srRcpt.unFrm.srSummary.srMid.szCreditTotal, srCPACSettleMiddle.szCreditTot);
        strcpy(srRcpt.unFrm.srSummary.srMid.szDebitCount, srCPACSettleMiddle.szDebitCnt);
        strcpy(srRcpt.unFrm.srSummary.srMid.szDebitTotal, srCPACSettleMiddle.szDebitTot);
        strcpy(srRcpt.unFrm.srSummary.srMid.szShiftNumber, srCPACSettleMiddle.szShiftNum);
        strcpy(srRcpt.unFrm.srSummary.srMid.szSurchrgeTotal, srCPACSettleMiddle.szSurCharge);
        strcpy(srRcpt.unFrm.srSummary.srMid.szAdjustCount, srCPACSettleMiddle.szAdjCnt);
        strcpy(srRcpt.unFrm.srSummary.srMid.szAdjustTotal, srCPACSettleMiddle.szAdjTot);
        strcpy(srRcpt.unFrm.srSummary.srMid.szReversalCount, srCPACSettleMiddle.szReversalCnt);
        strcpy(srRcpt.unFrm.srSummary.srMid.szReversalTotal, srCPACSettleMiddle.szReversalTot);
        strcpy(srRcpt.unFrm.srSummary.srMid.szNetCount, srCPACSettleMiddle.szNetCnt);
        strcpy(srRcpt.unFrm.srSummary.srMid.szNetTotal, srCPACSettleMiddle.szNetTot);
        lnBottomCond = srCPACSettleMiddle.lnMiddleCond;

        if (inPrintLines(pobPrinter, CPAC_GRANT_TOTAL_LABEL_START, CPAC_GRANT_TOTAL_LABEL_END, NO_BL_LINE, lnBottomCond) != VS_SUCCESS)
            return(VS_ERR);

        if (inPrintLines(pobPrinter, CPAC_SUMMARY_BOTTOM_START, CPAC_SUMMARY_BOTTOM_END, NO_BL_LINE, lnBottomCond) != VS_SUCCESS)
            return(VS_ERR);
    }

    /*   Printing Footer Message */

    vdGetReprintSettleFileName(szFileName, CPAC_FOOTER);

    if (inDBFileExists(szFileName) != VS_SUCCESS) {
        vdDisplayErrorMessage(REC_NOT_FOUND_ERR_MSG);
        return(VS_ERR);
    }

    inNoBytes = inDBReadRecord(szFileName, 1, (unsigned char *) &srCPACSettleBottom);
    if (inNoBytes < 0)
        return (VS_ERR);

    lnBottomCond = srCPACSettleBottom.lnBottomCond;

    if (inPrintLines(&obPrinter, CPAC_SETTLEMENT_STATUS_START, CPAC_SETTLEMENT_STATUS_END, NO_BL_LINE, lnBottomCond) != VS_SUCCESS)
        return(VS_ERR);

    if (inPrintLines(&obPrinter, CPAC_END_OF_REPORT_START, CPAC_END_OF_REPORT_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
        return(VS_ERR);
    return (VS_SUCCESS);
}


int inCPACCallReprintSettleReport(TRANSACTION_OBJECT* pobTran) {
#ifndef IMAM_REMOVE
    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }
    //if (!fGetEnablePrinter())
    //    return(VS_SUCCESS);

    inGetReport1Template();

    return(inCPACRePrintSettleReport(&obPrinter, pobTran));
#endif //IMAM_REMOVE
	return VS_SUCCESS;
}

void vdGetReprintSettleFileName(char* pszFileName,int inChoice) {
    char szBuf[FILENAME_SIZE + 1];

    memset(szBuf, 0x00, sizeof(szBuf));
    strcpy(szBuf, CPAC_RESETTLEMENT_REPORT_FILE);

    sprintf(pszFileName, "%s%02d%02d", szBuf, inGetMerchantNum(), (int) shGetHostGroupRef());

    switch (inChoice) {
    case 1 :
        strcat(pszFileName, ".hdr");
        break;

    case 2:
        strcat(pszFileName, ".bdy");
        break;

    case 3:
        strcat(pszFileName, ".ftr");
        break;
    default:
        strcat(pszFileName, ".hdr");
        break;
    }
}

// #endif /* TLFB */   (Made this feature as the part of CPAC Base Application)

/*   Saritha_b1.............End................Reprint Settlement Report */

/*********************************************************************************************
* @func int | inCPACReprintAnyReceiptOperation |
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

int inCPACReprintAnyReceiptOperation(TRANSACTION_OBJECT* pobTran) {
    /** /pdebug(("--inReprintAnyReceiptOperation--"));*/

    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }

    if (!fGetEnablePrinter())
        return(VS_SUCCESS);

    return(inCPACReprintRecpt(pobTran->srBKey.lnInvNum, &obPrinter, pobTran, 0));
}


void vdImamReformatDate(char *szDate)
{
	char buffer[20];
	memset(buffer, 0x00, sizeof(buffer));
	strncpy(buffer, (char *)szDate, 2);
	if (!strncmp((char *)&szDate[3], "01", 2)) {
		strcat(buffer, " JAN ");
	} else if (!strncmp((char *)&szDate[3], "02",2)) {
		strcat(buffer, " FEB ");
	} else if (!strncmp((char *)&szDate[3], "03", 2)) {
		strcat(buffer, " MAR ");
	} else if (!strncmp((char *)&szDate[3], "04", 2)) {
		strcat(buffer, " APR ");
	} else if (!strncmp((char *)&szDate[3], "05", 2)) {
		strcat(buffer, " MAY ");
	} else if (!strncmp((char *)&szDate[3], "06", 2)) {
		strcat(buffer, " JUNY ");
	} else if (!strncmp((char *)&szDate[3], "07", 2)) {
		strcat(buffer, " JULY ");
	} else if (!strncmp((char *)&szDate[3], "08", 2)) {
		strcat(buffer, " AUG ");
	} else if (!strncmp((char *)&szDate[3], "09", 2)) {
		strcat(buffer, " SEP ");
	} else if (!strncmp((char *)&szDate[3], "10", 2)) {
		strcat(buffer, " OCT ");
	} else if (!strncmp((char *)&szDate[3], "11", 2)) {
		strcat(buffer, " NOV ");
	} else if (!strncmp((char *)&szDate[3], "12", 2)) {
		strcat(buffer, " DEC ");
	}
	strncat(buffer, (char *)&szDate[6], 2);
	strcpy((char *)szDate, buffer);
}

#ifdef ICICI

int inPrintFailedSettlementMessage (TRANSACTION_OBJECT *pobTran, PRINTER_OBJECT *obPrinter)
{

	vdGetMessageFromFile(SETTLE_FAIL_ERR_MSG, srRcpt.szErrorMessage);
	strcat(srRcpt.szErrorMessage, " - ");
	strcat(srRcpt.szErrorMessage, szGetHostName());
	if(inPrintLines(obPrinter, 136, 139, NO_BL_LINE, 0x80000000L) != VS_SUCCESS)
          	return(VS_ERR);
	return VS_SUCCESS;
}

#endif  /* ICICI  */
